title: How to perform string validation & unit testing using google test in C++?
body: <p>I am trying to write some string validation functions such as</p>
  
  <ul>
  <li><p>check whether <strong>the string is NULL, Empty or have only spaces!</strong></p></li>
  <li><p>check whether <strong>the string is alphanumeric or uppercase!</strong></p></li>
  </ul>
  
  <p>I am only interested in strings with <strong>lowercase alphabets from a-z.(VALID strings)</strong> rest I want to block, so I have written the following functions:</p>
  
  <pre><code>std::string isEmpty(const std::string &amp;input){
      // empty string
      if (NULL ==input || input=="\0" || !input.size())
          return "";
  }
  std::string isMalfunctioned(const std::string &amp;input){
      for (int i = 0; i &lt; input.size(); ++i){
          // string is not a-z or alphanumeric or uppercase
          if ( input[i] &lt; 'a' || input[i] &gt; 'z'|| isalpha(input[i]) || isupper(input[i]) )
              return "";
      }
  }
  </code></pre>
  
  <p>and from the main function, I am just calling myFunc() using a reference to the input string &amp; it calls the validation function written above to notify a user of incoming invalid strings:</p>
  
  <pre><code>#include"myFunc.h"
  
  std::string myFunc(const std::string &amp; input){
      if( isEmpty(input)== "")
          std::cout&lt;&lt;"Empty input"&lt;&lt; std::endl;
      if( isMalfunctioned(input)== "")
          std::cout&lt;&lt;"malfunctioned input"&lt;&lt; std::endl;
      return input;
  }
  int main(){
      std::string input="1234";
      std::cout &lt;&lt; myFunc(input)&lt;&lt; std::endl;
      return  0;
  }
  </code></pre>
  
  <p><strong><em>My question:</em></strong></p>
  
  <ul>
  <li>First, I think my validation functions are not syntaticaly correct, since I am getting compile time errors as below, could anyone help in this regards?</li>
  </ul>
  
  <hr>
  
  <pre><code>mismatched types ‘const __gnu_cxx::__normal_iterator&lt;_
  Iterator, _Container&gt;’ and ‘long int’
  
  candidate: template&lt;class _Iterator,
   class _Container&gt; bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator&lt;_Iterat
  or, _Container&gt;&amp;, const __gnu_cxx::__normal_iterator&lt;_Iterator, _Container&gt;&amp;)
       operator==(const __normal_iterator&lt;_Iterator, _Container&gt;&amp; __lhs,
  </code></pre>
  
  <ul>
  <li><p>Second, I think, my validation functions are not fully covering my specifications. Any suggestion for it?</p></li>
  <li><p>Third, I have written some test cases using google test, but unable to interface with the above functionality, Any suggestions on what I am doing wrong &amp; how to correct them? Also, any suggestion on refactoring the code is also welcomed!</p></li>
  </ul>
  
  <hr>
  
  <pre><code>#include "myfunc.h"
  #include &lt;gtest/gtest.h&gt;
  
  TEST(testbundle, EmptyString){
    ASSERT_EQ("", myfunc(""));
  }
  
  TEST(testbundle, Malfunctioned){
    ASSERT_EQ("", myfunc("ad34534654"));
    ASSERT_EQ("", myfunc("!$#sadasfd1"));
  }
  
  TEST(testbundle, LowerCase){
    ASSERT_EQ("abbsbdbbdbdb", myfunc("abbsbdbbdbdb"));
  }
  TEST(PreliminaryTest, UpperCaseString){
    ASSERT_EQ("", myfunc("ASDFFGGGHH"));
  }
  
  int main(int argc, char **argv){
    testing::InitGoogleTest(&amp;argc, argv);
    return RUN_ALL_TESTS();
  }
  </code></pre>