Update unit tests to verify behavior of dynamic mode functions in non-dynamic builds


git-svn-id: https://cld2.googlecode.com/svn/trunk@163 b252ecd4-b096-bf77-eb8e-91563289f87e
diff --git a/internal/cld2_unittest.cc b/internal/cld2_unittest.cc
index 5a9c331..185051c 100644
--- a/internal/cld2_unittest.cc
+++ b/internal/cld2_unittest.cc
@@ -257,15 +257,19 @@
 
 #ifdef CLD2_DYNAMIC_MODE
 int RunTests (int flags, bool get_vector, const char* data_file) {
-#else
+#else // CLD2_DYNAMIC_MODE is not defined
 int RunTests (int flags, bool get_vector) {
-#endif
+#endif // ifdef CLD2_DYNAMIC_MODE
   fprintf(stdout, "CLD2 version: %s\n", CLD2::DetectLanguageVersion());
   InitHtmlOut(flags);
   bool any_fail = false;
-  
+
 #ifdef CLD2_DYNAMIC_MODE
   fprintf(stdout, "[DYNAMIC] Test running in dynamic data mode!\n");
+  if (!CLD2::isDataDynamic()) {
+    fprintf(stderr, "[DYNAMIC] *** Error: CLD2::isDataDynamic() returned false in a dynamic build!\n");
+    any_fail = true;
+  }
   bool dataLoaded = CLD2::isDataLoaded();
   if (dataLoaded) {
     fprintf(stderr, "[DYNAMIC] *** Error: CLD2::isDataLoaded() returned true prior to loading data from file!\n");
@@ -281,7 +285,16 @@
     any_fail = true;
   }
   fprintf(stdout, "[DYNAMIC] Data loaded, file-based tests commencing\n");
-#endif  
+#else // CLD2_DYNAMIC_MODE is not defined
+  if (CLD2::isDataDynamic()) {
+    fprintf(stderr, "*** Error: CLD2::isDataDynamic() returned true in a non-dynamic build!\n");
+    any_fail = true;
+  }
+  if (!CLD2::isDataLoaded()) {
+    fprintf(stderr, "*** Error: CLD2::isDataLoaded() returned false in non-dynamic build!\n");
+    any_fail = true;
+  }
+#endif // ifdef CLD2_DYNAMIC_MODE
 
   int i = 0;
   while (kTestPair[i].text != NULL) {
@@ -348,7 +361,14 @@
   any_fail |= !OneTest(flags, get_vector, UNKNOWN_LANGUAGE, kTeststr_en, strlen(kTeststr_en));
 
   fprintf(stdout, "[DYNAMIC] All dynamic-mode tests complete\n");  
-#endif  
+#else // CLD2_DYNAMIC_MODE is not defined
+  // These functions should do nothing, and shouldn't cause a crash. A warning is output to STDERR.
+  fprintf(stderr, "Checking that non-dynamic implementations of dynamic data methods are no-ops (ignore the warnings).\n");
+  CLD2::loadDataFromFile("this file doesn't exist");
+  CLD2::loadDataFromRawAddress(NULL, -1);
+  CLD2::unloadData();
+  fprintf(stderr, "Done checking non-dynamic implementations of dynamic data methods, care about warnings again.\n");
+#endif
 
   if (any_fail) {
     fprintf(stderr, "FAIL\n");
diff --git a/internal/compact_lang_det_impl.cc b/internal/compact_lang_det_impl.cc
index b59c7dc..fc1c333 100644
--- a/internal/compact_lang_det_impl.cc
+++ b/internal/compact_lang_det_impl.cc
@@ -150,15 +150,15 @@
 
   void loadDataFromFile(const char* fileName) {
     // This is a bug in the calling code.
-    fprintf(stderr, "WARNING: Dynamic mode not active, loadDataFromFile has no effect!");
+    fprintf(stderr, "WARNING: Dynamic mode not active, loadDataFromFile has no effect!\n");
   }
   void loadDataFromRawAddress(const void* rawAddress, const uint32_t length) {
     // This is a bug in the calling code.
-    fprintf(stderr, "WARNING: Dynamic mode not active, loadDataFromRawAddress has no effect!");
+    fprintf(stderr, "WARNING: Dynamic mode not active, loadDataFromRawAddress has no effect!\n");
   }
   void unloadData() {
     // This is a bug in the calling code.
-    fprintf(stderr, "WARNING: Dynamic mode not active, unloadData has no effect!");
+    fprintf(stderr, "WARNING: Dynamic mode not active, unloadData has no effect!\n");
   }
 
 #endif // #ifdef CLD2_DYNAMIC_MODE
diff --git a/internal/compile_and_test_all.sh b/internal/compile_and_test_all.sh
index a1ba529..002b198 100755
--- a/internal/compile_and_test_all.sh
+++ b/internal/compile_and_test_all.sh
@@ -22,9 +22,9 @@
 echo "--> [2 of 7] Testing results of compile.sh..."
 echo "--> compact_lang_det_test_chrome... "
 echo "this is some english text" | ./compact_lang_det_test_chrome
-echo -n "--> cld2_unittest... "
+echo "--> cld2_unittest... "
 ./cld2_unittest > /dev/null
-echo -n "--> cld2_unittest_avoid... "
+echo "--> cld2_unittest_avoid... "
 ./cld2_unittest_avoid > /dev/null
 
 # ----------------------------------------------------------------------------
@@ -37,9 +37,9 @@
 echo "--> [5 of 7] Testing results of compile_full.sh..."
 echo "--> compact_lang_det_test_full... "
 echo "this is some english text" | ./compact_lang_det_test_full
-echo -n "--> cld2_unittest_full... "
+echo "--> cld2_unittest_full... "
 ./cld2_unittest_full > /dev/null
-echo -n "--> cld2_unittest_full_avoid... "
+echo "--> cld2_unittest_full_avoid... "
 ./cld2_unittest_full_avoid > /dev/null
 
 # ----------------------------------------------------------------------------
@@ -52,7 +52,7 @@
 echo "--> [7 of 7] Testing results of compile_dynamic.sh..."
 echo "--> compact_lang_det_dynamic_test_chrome... "
 echo "this is some english text" | ./compact_lang_det_dynamic_test_chrome --data-file cld2_data.bin
-echo -n "--> cld2_dynamic_unittest... "
+echo "--> cld2_dynamic_unittest... "
 ./cld2_dynamic_unittest --data-file cld2_data.bin > /dev/null
 
 trap - INT TERM EXIT