Skip to content

Commit

Permalink
Update unit tests to verify behavior of dynamic mode functions in non…
Browse files Browse the repository at this point in the history
…-dynamic builds

git-svn-id: https://cld2.googlecode.com/svn/trunk@163 b252ecd4-b096-bf77-eb8e-91563289f87e
  • Loading branch information
[email protected] committed Jul 25, 2014
1 parent b661afa commit 00d28e3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
30 changes: 25 additions & 5 deletions internal/cld2_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,19 @@ void FinishHtmlOut(int flags) {

#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");
Expand All @@ -281,7 +285,16 @@ int RunTests (int flags, bool get_vector) {
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) {
Expand Down Expand Up @@ -348,7 +361,14 @@ int RunTests (int flags, bool get_vector) {
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");
Expand Down
6 changes: 3 additions & 3 deletions internal/compact_lang_det_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ extern const short kAvgDeltaOctaScore[];

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
Expand Down
10 changes: 5 additions & 5 deletions internal/compile_and_test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ echo "--> [1 of 7] Invoking: compile.sh..."
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

# ----------------------------------------------------------------------------
Expand All @@ -37,9 +37,9 @@ echo "--> [4 of 7] Invoking: compile_full.sh..."
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

# ----------------------------------------------------------------------------
Expand All @@ -52,7 +52,7 @@ echo "--> [6 of 7] Verifying dynamic data in cld2_data.bin..."
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
Expand Down

0 comments on commit 00d28e3

Please sign in to comment.