1 // Copyright 2017 Google Inc. All Rights Reserved.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 
4 // Simple unit test for DoStuff().
5 // This unit test does not cover the existing bug in DoStuff(),
6 // unless you pass an extra parameter ("BUG").
7 #include "my_api.h"
8 
9 #include <cassert>
10 #include <iostream>
11 
TestDoStuff(const std::string & str,size_t Expected)12 void TestDoStuff(const std::string &str, size_t Expected) {
13   size_t Result = DoStuff(str);
14   std::cerr << str << " => " << Result << std::endl;
15   assert(Result == Expected);
16 }
17 
main(int argc,char ** argv)18 int main(int argc, char **argv) {
19   // Test some simple inputs, verify the output.
20   TestDoStuff("", 0);
21   TestDoStuff("foo", 1);
22   TestDoStuff("omg", 1);
23   TestDoStuff("bar", 1);
24   TestDoStuff("ouch", 1);
25   TestDoStuff("foobar", 3);
26   TestDoStuff("foouchbar", 4);
27   if (argc == 2 && std::string(argv[1]) == "BUG") {
28     // This is the missing test that actually triggers the bug.
29     TestDoStuff("foouchbaromg", 4);
30   }
31 }
32