diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /vdstestlib/src/tests |
Publish
Diffstat (limited to 'vdstestlib/src/tests')
-rw-r--r-- | vdstestlib/src/tests/cppunit/.gitignore | 4 | ||||
-rw-r--r-- | vdstestlib/src/tests/cppunit/CMakeLists.txt | 9 | ||||
-rw-r--r-- | vdstestlib/src/tests/cppunit/DESC | 1 | ||||
-rw-r--r-- | vdstestlib/src/tests/cppunit/FILES | 1 | ||||
-rw-r--r-- | vdstestlib/src/tests/cppunit/cppunittest.cpp | 25 | ||||
-rw-r--r-- | vdstestlib/src/tests/cppunit/testrunner.cpp | 11 | ||||
-rw-r--r-- | vdstestlib/src/tests/dirconfig/.gitignore | 5 | ||||
-rw-r--r-- | vdstestlib/src/tests/dirconfig/CMakeLists.txt | 8 | ||||
-rw-r--r-- | vdstestlib/src/tests/dirconfig/DESC | 1 | ||||
-rw-r--r-- | vdstestlib/src/tests/dirconfig/FILES | 1 | ||||
-rw-r--r-- | vdstestlib/src/tests/dirconfig/dirconfigtest.cpp | 105 |
11 files changed, 171 insertions, 0 deletions
diff --git a/vdstestlib/src/tests/cppunit/.gitignore b/vdstestlib/src/tests/cppunit/.gitignore new file mode 100644 index 00000000000..ec991c2f0cd --- /dev/null +++ b/vdstestlib/src/tests/cppunit/.gitignore @@ -0,0 +1,4 @@ +.depend +Makefile +testrunner +vdstestlib_testrunner_app diff --git a/vdstestlib/src/tests/cppunit/CMakeLists.txt b/vdstestlib/src/tests/cppunit/CMakeLists.txt new file mode 100644 index 00000000000..01356972a56 --- /dev/null +++ b/vdstestlib/src/tests/cppunit/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(vdstestlib_testrunner_app + SOURCES + testrunner.cpp + cppunittest.cpp + DEPENDS + vdstestlib +) +vespa_add_test(NAME vdstestlib_testrunner_app NO_VALGRIND COMMAND vdstestlib_testrunner_app) diff --git a/vdstestlib/src/tests/cppunit/DESC b/vdstestlib/src/tests/cppunit/DESC new file mode 100644 index 00000000000..247fc25faf0 --- /dev/null +++ b/vdstestlib/src/tests/cppunit/DESC @@ -0,0 +1 @@ +Test of the CPPUNIT tools. diff --git a/vdstestlib/src/tests/cppunit/FILES b/vdstestlib/src/tests/cppunit/FILES new file mode 100644 index 00000000000..468a6bfb10a --- /dev/null +++ b/vdstestlib/src/tests/cppunit/FILES @@ -0,0 +1 @@ +programoptions.cpp diff --git a/vdstestlib/src/tests/cppunit/cppunittest.cpp b/vdstestlib/src/tests/cppunit/cppunittest.cpp new file mode 100644 index 00000000000..07c02f6dcdc --- /dev/null +++ b/vdstestlib/src/tests/cppunit/cppunittest.cpp @@ -0,0 +1,25 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include <vespa/vdstestlib/cppunit/macros.h> + +namespace vespalib { + +struct CppunitTest : public CppUnit::TestFixture { + + void testSomething(); + + CPPUNIT_TEST_SUITE(CppunitTest); + CPPUNIT_TEST(testSomething); + CPPUNIT_TEST_SUITE_END(); + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(CppunitTest); + +void +CppunitTest::testSomething() +{ + CPPUNIT_ASSERT_EQUAL_MESSAGE("hmm", "foo", "foo"); +} + +} // vespalib diff --git a/vdstestlib/src/tests/cppunit/testrunner.cpp b/vdstestlib/src/tests/cppunit/testrunner.cpp new file mode 100644 index 00000000000..1ba7be7790e --- /dev/null +++ b/vdstestlib/src/tests/cppunit/testrunner.cpp @@ -0,0 +1,11 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <vespa/fastos/fastos.h> +#include <vespa/vdstestlib/cppunit/cppunittestrunner.h> + +int main(int argc, char **argv) +{ + vdstestlib::CppUnitTestRunner testRunner; + return testRunner.run(argc, argv); +} + diff --git a/vdstestlib/src/tests/dirconfig/.gitignore b/vdstestlib/src/tests/dirconfig/.gitignore new file mode 100644 index 00000000000..d19c58dc3e5 --- /dev/null +++ b/vdstestlib/src/tests/dirconfig/.gitignore @@ -0,0 +1,5 @@ +.depend +Makefile +dirconfig.tmp +dirconfig_test +vdstestlib_dirconfig_test_app diff --git a/vdstestlib/src/tests/dirconfig/CMakeLists.txt b/vdstestlib/src/tests/dirconfig/CMakeLists.txt new file mode 100644 index 00000000000..1cd06c06930 --- /dev/null +++ b/vdstestlib/src/tests/dirconfig/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(vdstestlib_dirconfig_test_app + SOURCES + dirconfigtest.cpp + DEPENDS + vdstestlib +) +vespa_add_test(NAME vdstestlib_dirconfig_test_app NO_VALGRIND COMMAND vdstestlib_dirconfig_test_app) diff --git a/vdstestlib/src/tests/dirconfig/DESC b/vdstestlib/src/tests/dirconfig/DESC new file mode 100644 index 00000000000..2a3a952a471 --- /dev/null +++ b/vdstestlib/src/tests/dirconfig/DESC @@ -0,0 +1 @@ +Tests that dirconfig class works correctly. diff --git a/vdstestlib/src/tests/dirconfig/FILES b/vdstestlib/src/tests/dirconfig/FILES new file mode 100644 index 00000000000..6e94447a2bd --- /dev/null +++ b/vdstestlib/src/tests/dirconfig/FILES @@ -0,0 +1 @@ +dirconfigtest.cpp diff --git a/vdstestlib/src/tests/dirconfig/dirconfigtest.cpp b/vdstestlib/src/tests/dirconfig/dirconfigtest.cpp new file mode 100644 index 00000000000..d373b7de7e4 --- /dev/null +++ b/vdstestlib/src/tests/dirconfig/dirconfigtest.cpp @@ -0,0 +1,105 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <vespa/fastos/fastos.h> +#include <vespa/vdstestlib/cppunit/dirconfig.h> + +#include <fstream> +#include <iostream> +#include <vespa/log/log.h> +#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/vespalib/util/exceptions.h> + +LOG_SETUP("dirconfig_test"); + +using namespace vdstestlib; + +namespace vespalib { + +class Test : public vespalib::TestApp +{ +public: + void testNormalUsage(); + int Main(); +}; + +int +Test::Main() +{ + TEST_INIT("dirconfig_test"); + srandom(1); + testNormalUsage(); + TEST_DONE(); +} + +#define ASSERT_FILE_CONTENT(file, content) \ +{ \ + std::ifstream in(file); \ + std::ostringstream ost; \ + std::string line; \ + while (getline(in, line, '\n')) { \ + ost << line << '\n'; \ + } \ + EXPECT_EQUAL(content, ost.str()); \ +} + +void Test::testNormalUsage() { + DirConfig config1; + DirConfig config2; + + EXPECT_EQUAL("dir:dirconfig.tmp/1", config1.getConfigId()); + EXPECT_EQUAL("dir:dirconfig.tmp/2", config2.getConfigId()); + + try{ + config1.getConfig("testconfig"); + TEST_FATAL("Not supposed to get here"); + } catch (vespalib::Exception& e) { + EXPECT_EQUAL("No config named testconfig", e.getMessage()); + } + DirConfig::Config& file1(config1.addConfig("testconfig")); + try{ + config1.addConfig("testconfig"); + TEST_FATAL("Not supposed to get here"); + } catch (vespalib::Exception& e) { + EXPECT_EQUAL("There is already a config named testconfig", + e.getMessage()); + } + EXPECT_EQUAL(&file1, &config1.getConfig("testconfig")); + file1.set("intval", "5"); + file1.set("intval", "7"); + file1.set("stringval", "\"foo\""); + file1.set("tmpval", "4"); + file1.remove("tmpval"); + // Trigger publish + config1.getConfigId(); + + ASSERT_FILE_CONTENT("dirconfig.tmp/1/testconfig.cfg", + "intval 7\n" + "stringval \"foo\"\n"); + + DirConfig::Config& file2(config2.addConfig("testconfig")); + file2.set("longval", "6"); + file2.clear(); + file2.set("intval", "4"); + + DirConfig::Config& file3(config1.addConfig("config2")); + file3.set("intval", "3"); + file3.set("myarray[2]"); + file3.set("myarray[0].foo", "4"); + file3.set("myarray[1].foo", "2"); + + config1.publish(); + config2.publish(); + + ASSERT_FILE_CONTENT("dirconfig.tmp/2/testconfig.cfg", + "intval 4\n"); + ASSERT_FILE_CONTENT("dirconfig.tmp/1/config2.cfg", + "intval 3\n" + "myarray[2]\n" + "myarray[0].foo 4\n" + "myarray[1].foo 2\n"); + +} + +} // vespalib + +TEST_APPHOOK(vespalib::Test) |