Stun Server  Compliant with the latest RFCs including 5389, 5769, and 5780
discover the local host's own external IP address
testcmdline.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2011 John Selbie
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 
18 #include "commonincludes.hpp"
19 #include "cmdlineparser.h"
20 #include "unittest.h"
21 #include "testcmdline.h"
22 
23 
24 // This test validates that the CCmdLineParser works correctly
26 {
27  HRESULT hr = S_OK;
28 
29  //char* argv[] = {(char*)"app", (char*)"--zebra", (char*)"--yak=123", (char*)"--walrus=456", (char*)"--vulture"};
30  const char* argv[5] = {};
31  argv[0] = "app";
32  argv[1] = "--zebra";
33  argv[2] = "--yak=123";
34  argv[3] = "--walrus=456";
35  argv[4] = "--vulture";
36 
37 
38  int argc = ARRAYSIZE(argv);
39  bool fErrorFlag = false;
40 
41  std::string strZebra;
42  std::string strYak;
43  std::string strWalrus;
44  std::string strVulture;
45  std::string strAardvark;
46 
47 
48  CCmdLineParser parser;
49 
50  parser.AddOption("aardvark", 1, &strAardvark);
51  parser.AddOption("vulture", 0, &strVulture);
52  parser.AddOption("walrus", 1, &strWalrus);
53  parser.AddOption("yak", 2, &strYak);
54  parser.AddOption("zebra", 2, &strZebra);
55 
56  parser.ParseCommandLine(argc, (char**)argv, 1, &fErrorFlag);
57 
58  ChkIf(fErrorFlag, E_FAIL);
59 
60  ChkIf(strAardvark.length() > 0, E_FAIL);
61  ChkIf(strVulture.length() == 0, E_FAIL);
62  ChkIf(strWalrus != "456", E_FAIL);
63  ChkIf(strYak != "123", E_FAIL);
64  ChkIf(strZebra != "1", E_FAIL);
65 
66 Cleanup:
67  return hr;
68 }
#define S_OK
Definition: hresult.h:46
#define ARRAYSIZE(arr)
#define ChkIf(expr, hrerror)
Definition: chkmacros.h:63
int32_t HRESULT
Definition: hresult.h:22
HRESULT ParseCommandLine(int argc, char **argv, int startindex, bool *fParseError)
#define E_FAIL
Definition: hresult.h:56
HRESULT AddOption(const char *pszName, int has_arg, std::string *pStrResult)