]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Modified test code to accept multiple parameters.
authorLinux Karlsson <karlsson@ntp.org>
Tue, 27 Jul 2010 16:08:05 +0000 (18:08 +0200)
committerLinux Karlsson <karlsson@ntp.org>
Tue, 27 Jul 2010 16:08:05 +0000 (18:08 +0200)
bk: 4c4f0465hT-B3qCQ5YNeprd8ICx6OQ

tests/main.cpp
tests/main.h
tests/sntp/Makefile.am
tests/sntp/kodFile.cpp
tests/sntp/test-driver

index 7409c9bb87611dbba90638534d68fdd950831896..98395ccb521e058a3c6eefbc1c5c62b438e00130 100644 (file)
@@ -3,18 +3,20 @@
 int main(int argc, char **argv) {
        ::testing::InitGoogleTest(&argc, argv);
 
-       // Some tests makes use of an extra parameter passed to the tests
-       // executable. Save this param as a static member of the base class.
+       // Some tests makes use of extra parameters passed to the tests
+       // executable. Save these params as static members of the base class.
        if (argc > 1) {
-               ntptest::SetExtraParam(argv[1]);
+               ntptest::SetExtraParams(1, argc-1, argv);
        }
        
        return RUN_ALL_TESTS();
 }
 
-std::string ntptest::m_param = "";
+std::vector<std::string> ntptest::m_params;
 
-void ntptest::SetExtraParam(const char* param)
+void ntptest::SetExtraParams(int start, int count, char** argv)
 {
-       m_param = param;
+       for (int i=0; i<count; i++) {
+               m_params.push_back(argv[i+start]);
+       }
 }
index ab91d1c0b2294993ddf22658e01b2914f3a0ee3d..3b3740246d11cb50ef99c04e9ad6a58dad94e28a 100644 (file)
@@ -3,10 +3,11 @@
 #include "config.h"
 
 #include <string>
+#include <vector>
 
 class ntptest : public ::testing::Test {
 public:
-       static void SetExtraParam(const char* param);
+       static void SetExtraParams(int start, int count, char** argv);
 protected:
-       static std::string m_param;
+       static std::vector<std::string> m_params;
 };
index a7eddc4d04c9c1cc003e7427d278596661d69f88..d823e44a4f40df85d145b7a9ec80d7ed77b9df76 100644 (file)
@@ -25,7 +25,7 @@ INCLUDES = $(LIBOPTS_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/lib/isc/inc
 
 TESTS = 
 
-TESTS_ENVIRONMENT = $(top_srcdir)/tests/sntp/test-driver $(abs_srcdir)/data
+TESTS_ENVIRONMENT = $(top_srcdir)/tests/sntp/test-driver $(abs_srcdir)/data $(abs_builddir)/data
 
 if !NTP_CROSSCOMPILE
 TESTS += $(check_PROGRAMS)
index dde4a2c98a863fce4de8c79d807cc632a50e3897..b3791158ca6ed7111dee5ed431e144c38b606ab0 100644 (file)
@@ -16,8 +16,12 @@ extern char* kod_db_file;
 
 class kodFileTest : public sntptest {
 protected:
-       std::string CreatePath(const char* filename) {
-               std::string path = m_param;
+       std::string CreatePath(const char* filename, int argument) {
+               std::string path;
+
+               if (m_params.size() >= argument + 1) {
+                       path = m_params[argument];
+               }
 
                if (path[path.size()-1] != DIR_SEP && !path.empty()) {
                        path.append(1, DIR_SEP);
@@ -45,13 +49,13 @@ protected:
 };
 
 TEST_F(kodFileTest, ReadEmptyFile) {
-       kod_init_kod_db(CreatePath("kod-test-empty").c_str());
+       kod_init_kod_db(CreatePath("kod-test-empty", 0).c_str());
 
        EXPECT_EQ(0, kod_db_cnt);
 }
 
 TEST_F(kodFileTest, ReadCorrectFile) {
-       kod_init_kod_db(CreatePath("kod-test-correct").c_str());
+       kod_init_kod_db(CreatePath("kod-test-correct", 0).c_str());
        
        EXPECT_EQ(2, kod_db_cnt);
 
@@ -69,7 +73,7 @@ TEST_F(kodFileTest, ReadCorrectFile) {
 }
 
 TEST_F(kodFileTest, ReadFileWithBlankLines) {
-       kod_init_kod_db(CreatePath("kod-test-blanks").c_str());
+       kod_init_kod_db(CreatePath("kod-test-blanks", 0).c_str());
 
        EXPECT_EQ(3, kod_db_cnt);
 
index 44b0aeb72e0566bab7a6f12cc4e3304268c82fb2..d6c5ced9af5ebdb657616bdd5115f7d819872f56 100755 (executable)
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-exec "$2" "$1"
+exec "$3" "$1" "$2"