gflags_test.cc 978 字节
Newer Older
1 2 3 4 5 6 7 8 9
#include <iostream>
#include <string>

#include "gflags/gflags.h"
#include "gtest/gtest.h"

DEFINE_bool(verbose, false, "Display program name before message");
DEFINE_string(message, "Hello world!", "Message to print");

10
static bool IsNonEmptyMessage(const char *flagname, const std::string &value) {
11 12 13 14 15 16 17 18 19 20 21 22
  return value[0] != '\0';
}
DEFINE_validator(message, &IsNonEmptyMessage);

namespace third_party {
namespace gflags_test {

TEST(GflagsTest, ParseAndPrint) {
  gflags::SetUsageMessage("some usage message");
  gflags::SetVersionString("1.0.0");
  int argc = 1;
  char program_name[] = "gflags_test";
23
  char **argv = new char *[2];
24 25
  argv[0] = program_name;
  argv[1] = NULL;
26
  gflags::ParseCommandLineFlags(&argc, reinterpret_cast<char ***>(&argv), true);
27 28 29 30 31 32 33
  EXPECT_EQ("gflags_test", std::string(gflags::ProgramInvocationShortName()));
  EXPECT_EQ("Hello world!", FLAGS_message);
  gflags::ShutDownCommandLineFlags();
}

}  // namespace gflags_test
}  // namespace third_party