Saturday, August 14, 2010

Visual C++ and Googletest

This post will probably only be of interest to Chip, but I'm writing it anyway.

  • First step was to download my software packages. I got visual C++ 2010 from http://www.microsoft.com/express/Windows/. Then I got the version 1.5 zip of Googletest from http://code.google.com/p/googletest/downloads/list.
  • Visual C++ installed without a hitch, although there is a mandatory reboot required by the install. Googletest doesn't even require an install, you just unzip the package and stick it somewhere.
  • Looking for a pattern to follow, I found http://www.freshclickmedia.com/blog/2009/10/getting-started-with-googletest-the-google-c-testing-framework/. This is a short video, and being a video is both it's greatest strength and weakness. If you use it, you'll probably be rewinding a lot and cursing the inability to cut and paste. However, watching someone clicking on the interface is very useful. This really covers everything you need to get up and running, but you have to play close attention. I cost myself some time searching for files that were pointed out in the video by not rewinding far enough.
  • The fist step is to compile the vcpp version of Googletest. The google example was probably built as a vcpp 2008 project because my version told me I needed to convert the project. At first the conversion failed because the project was read-only. I figured that I had the original zip, so it wouldn't hurt to make these files read/write. After I did this the project built without any issues.
  • There are two "gotchas" I missed the first time through. The first is the runtime library. Multi-threaded debug and multi-threaded debug dll are not the same thing. There is a warning about linker errors if you get these wrong, but the warning in the video isn't really stern enough. The other is that the 2 libraries built when you compile Googletest ~\msvc\gtest\Debug where ~ is wherever you unzipped Googletest. This is the part where I didn't rewind far enough and had to hunt for these files.
  • I started a new console project. You need to add the two libraries, gtest_maind and gtestd to Configuration Properties | Linker | Input.
  • Next, under Configuration Properties | c/c++ | General, add the ~\googletest\include to Addition Include Directories.
  • Time for the second issue I ran into, I didn't set Configuration Properties | c/c++ | Code Generation to Multi-threaded Debug (/MTd). The default is Multi-threaded Debug DLL (/MDd) which is very similar looking, but not quite the same.
  • I've seen a few ways to include the tests. The one that seems the most intuitive to me is to set up a header file which declares a test class and has the constructor, destructor, SetUp, and TearDown methods. This creates a class which can be used as a test suite. The easiest way to get started is to paste in some boiler plate code from http://code.google.com/p/googletest/wiki/GoogleTestPrimer.
  • The actual tests go into a cpp file with the same name as the header. Here is a simple test set up by the TEST_F Macro: TEST_F (SimpleTest,DemoTest1) { ASSERT_EQ(1,1); }
  • Two lines of code go into the main function to cause the tests to run:
  • ::testing::InitGoogleTest(&argc, argv);
  • return RUN_ALL_TESTS();
  • One thing I like about this is that you just tell it to run all tests, you don't have to list each test suite you created. For my simple, just get it running, project, this doesn't matter, but for a large project, automatic inclusion seems like a very nice feature.
  • My first try was a complete loss because of the run time library mistake I made. My second try, I realized my mistake and I got to see the test results pop up at the end of my run.

Monday, August 9, 2010

Books I've Decided I Need to Read

After going through several lists of top 100 books, I decided that there are some things I need to read that I haven't. In no particular order.

  • Atlas Shrugged - Ayn Rand When I told someone at work about my lists, he had only two. This was one of them. I do remember from high school that the person who read this when we each picked a different book from a list enjoyed it.
  • Illusions - Richard Bach This was the other book that the guy from work would have put on his list. Atlas Shrugged would have probably ended up on my list without his recommendation; this would not have. (In fact, I wouldn't have even known about it.)
  • To Kill a Mockingbird - Harper Lee My English class never read this, but the people in the classes that did liked it. On the theory that high school students don't like anything I need to read this.
  • Catch-22 - Joseph Heller This book has spawned an English phrase and I think I'd like it for the irony contained within it.
  • The Catcher in the Rye - J. D. Salinger See the comments for To Kill a Mockingbird
  • Slaughterhouse Five - Kurt Vonnegut I thought I had read a Vonnegut short story or two, but when I checked on the Internet, the story I was thinking of was by a different author.
  • The Godfather - Mario Puzo My dad doesn't read many books, but my mom said he stayed up all night reading this one.
  • The Maltese Falcon - Dashiell Hammett I keep coming across the phrase "hard boiled" when I look for reasons to read this.
  • Kidnapped - Robert Lewis Stephenson I bought this thinking it would be good to read a classic. I need to make myself read it and decide if I was correct.
  • The Canterbury Tales - Geoffrey Chaucer I got this one from a pile that was otherwise headed to Half Price Books. This has some of the appeal of The Odyssey (although not nearly as old) in that people are still reading it many centuries after it was written.
  • Le Morte de Arthur - Sir Thomas Malory I've read several versions of Arthurian legends, but I'm fairly certain that I haven't read this collection.
  • Adventures of Huckleberry Finn - Mark Twain This is mainly on the list because I feel the need to include a uniquely American writer.
In addition to books I have never read, I decided I need to re-read Hitchhiker's Guide to the Galaxy and A Wrinkle in Time while composing my book lists.



Saturday, August 7, 2010

Books (I Think) Everyone Should Read Part II

Last time I published the books that didn't fit onto my should read list for one reason or another. This list is the 10 books I would say everyone should read.

  • Frankenstein - Mary Shelley This book is embedded in our culture mainly through movies. You could argue that Dracula is as well, but I think this book has more universal appeal with the theme of there are some things man was just not meant to know.
  • Gulliver's Travels - Jonathan Swift Gulliver's first journey to the land of the Lilliput gave us a word, Lilliputian. If giving us a word and providing iconic images of a man tied down by thousands of strings isn't enough, the satire in all four is still valid today. We've still got countries going to war over things just as foolish as which end of the egg to open. Also, it was someone who was not at all familiar with this book that got me thinking about a must read list.
  • The Oddessy of Homer The fact that people are still reading this after over 2000 years speaks for itself. I think this is the more readable of the first part of the story, the Illiad. You couldn't go wrong reading any of the major classic epics, but I think this one is a must read.
  • A Wrinkle in Time - Madeleine L'Engle How can you not put a book on the list which starts with: "It was a dark and stormy night." Many books have stories about a secret struggle between good and evil, The Dark Is Rising comes to mind, but I think that this is a particularly well written one. It was also the first book I ever read that used a four dimensional construct known as a tesseract . Traveling through one is the namesake wrinkle.
  • A Wizard of Earthsea - Ursula K. Le Guin Long before J. K. Rowling had ever gone into the coffee shop to write about Harry Potter, Le Guin wrote this book to answer the question: Where do wizards come from. When I was in second grade, this book was featured in a Reading Rainbow type show. Several of the boys in the class with me had been excited by the excerpt of the book which featured the Wizard's battle with a family of hatching dragons. We worked out a plan to get a copy of the book and the order in which we would read it. As far as I know, I'm the only one who ever got a hold of the book and read it. Rereading the book as an adult, I realized I that I had absorbed much of the philosophy of the book without even realizing it.
  • Dune - Frank Herbert I've lost track of the number of times I've read this book. There are so many ideas contained in it. Politics, religion, planning, revenge, loyalty, hero worship, human thought vs. thinking machines, ecology. Forget the David Lynch movie, this is one of the finest books ever written.
  • Hitchhiker's Guide to the Galaxy - Douglas Adams Usually I don't want too much humor in my novels, but this is an exception. In what other book can you learn the answer to Life, the Universe, and Everything?
  • Brave New World - Aldous Huxley In some ways, I feel like we're living in the dystopian world predicted by this novel. It's amazing that it was written in the 1930's, it feels like a book that could have been written today.
  • Lord of the Rings - J. R. R. Tolkein I know this is a trilogy, but that's because the publisher wouldn't put it out as a single volume. There is probably a big section at your favorite bookstore that wouldn't exist if Tolkein hadn't written this tale of middle earth. While it is a work of fiction, the world of Middle Earth is so well thought out, it reads like a history of another world. While inventing languages for the people of world to speak isn't a prerequisite for great literature, it does add something to this story.
  • Alice in Wonderland - Lewis Carroll This is another story with imagery embedded into the culture. The rabbit in a waist coat, the Cheshire cat, and little bits of food and drink with the labels eat me and drink me should be familiar to everyone.
One thing that struck me after I had assembled this list is how many of the must reads I've picked are often put in the young readers section of a bookstore.

Wednesday, August 4, 2010

Books (I Think) Everyone Should Read Part I

I'm going to start of with books that didn't make the list. I was going to create a top 10 list, and promptly put 20 items on it. I'm not even going to start on books that I think are excellent, but lack some feature of universal appeal.

So, in short, while you should read these, I've got another list of books that I think are more deserving of being read.

  • Ender's Game - Orson Scott Card If two alien races meet but cannot communicate, is one fated to exterminate the other? To what limits can you go to defend your entire species? This would probably be the first novel to move up to the main list if I expanded to 11, but I think this lacks just a touch of universal appeal.
  • Aesop's Fables - Not on the list because it's not a novel, but everyone should be able to come up several fables off the top of their head. "Grasp at the shadow and loose the substance", "Try to please everyone and you'll end up pleasing no one", "sour grapes", "slow and steady wins the race"
  • Grimm's Fairy Tales - See above, everyone should be able to come up with several Fairy Tales off the top of their head too.
  • 1001 Nights - Again, not a novel and not as familiar to Western culture as the first two, but still full of stories people are familiar with.
  • Neuromancer - William Gibson A novel about crime, drug abuse, artificial intelligence, and great wealth. Apart from that, it essentially launched an entire sub-genre of fiction, cyberpunk. It's amazing to think that this book was written before the 90's internet boom.
  • Diamond Age - Neal Stephenson If Neuromancer is a book about the age of computers, this is a book about the age of nanotechnology. In this novel, diamond is literally cheaper than glass. Carbon atoms are lined up in the proper pattern by a fabricator to make diamond, but glass requires someone heating up sand in a fire. This novel raises questions of society, culture, education, and what it means to be a parent.
  • Little House on the Prairie - There is so much science fiction on my list, I thought for a long time on something to balance it. I think this is a good choice. Everyone probably knows the title of the book from the Michael Landon TV Show, and it's an interesting slice of life from 140 years ago.
  • Starship Troopers - Robert A. Heinlein First, forget everything and anything you might know about the Paul Verhoeven movie. In some ways, this is not on the main list because it is more political manifesto than space opera, and in other ways because the solution to organizing a society can't be as easy as Heinlein makes it out to be. However, reading this book will make you think.
  • Do Androids Dream of Electric Sheep - Philip K. Dick First of all, this is the book that inspired the movie Bladerunner. Second, it's the only book on my list that thinks about the question of how our relationship (after we've nuked the vast majority of them to extinction) with animals separates humans from androids, unless of course, the android hunting Deckard, who is very fond of his electric sheep, is an android himself.
  • The Omnivore's Dilemma - Michael Pollan - This non fiction, but you'll never look at a chicken nugget or think about a feed lot or a corn farm the same as you did before reading this book.