Check if InitGoogleLogging is not called twice.
author <shinichiro.hamaji@gmail.com> <>
Fri, 10 Apr 2009 16:15:53 +0000 (16:15 +0000)
committer <shinichiro.hamaji@gmail.com> <>
Fri, 10 Apr 2009 16:15:53 +0000 (16:15 +0000)
git-svn-id: https://google-glog.googlecode.com/svn/trunk@47 eb4d4688-79bd-11dd-afb4-1d65580434c0

src/utilities.cc
src/utilities_unittest.cc

index 3efe7795963136e28167e26194e4f64c1abdd839..7769634b98d005a6d08a9ffe443d2a47c43e773c 100644 (file)
@@ -309,6 +309,8 @@ void SetCrashReason(const CrashReason* r) {
 }  // namespace glog_internal_namespace_
 
 void InitGoogleLogging(const char* argv0) {
+  CHECK(!IsGoogleLoggingInitialized())
+      << "You called InitGoogleLogging() twice!";
   const char* slash = strrchr(argv0, '/');
 #ifdef OS_WINDOWS
   if (!slash)  slash = strrchr(argv0, '\\');
index a2fb31b34440c1eea5c9c0b13be940be2bc5811d..7b796190e3922c3e91688048c756479892df2e53 100644 (file)
 
 using namespace GOOGLE_NAMESPACE;
 
-TEST(sync_val_compare_and_swap, utilities) {
+TEST(utilities, sync_val_compare_and_swap) {
   bool now_entering = false;
   EXPECT_FALSE(sync_val_compare_and_swap(&now_entering, false, true));
   EXPECT_TRUE(sync_val_compare_and_swap(&now_entering, false, true));
   EXPECT_TRUE(sync_val_compare_and_swap(&now_entering, false, true));
 }
 
+TEST(utilities, InitGoogleLoggingDeathTest) {
+  ASSERT_DEATH(InitGoogleLogging("foobar"), "");
+}
+
 int main(int argc, char **argv) {
   InitGoogleLogging(argv[0]);
   InitGoogleTest(&argc, argv);