Browse Source

[4088] EvalContext unit-test added.

Tomek Mrugalski 9 years ago
parent
commit
8c92106662

+ 9 - 6
src/lib/eval/eval_context.cc

@@ -1,16 +1,16 @@
-#include "eval_context.h"
-#include "parser.h"
-
+#include <eval/eval_context.h>
+#include <eval/parser.h>
+#include <exceptions/exceptions.h>
 #include <fstream>
 
-EvalContext::EvalContext ()
+EvalContext::EvalContext()
   : trace_scanning (false), trace_parsing (false)
 {
   variables["one"] = 1;
   variables["two"] = 2;
 }
 
-EvalContext::~EvalContext ()
+EvalContext::~EvalContext()
 {
 }
 
@@ -30,8 +30,11 @@ int
 EvalContext::parseString(const std::string& str)
 {
     remove("/tmp/eval");
-    std::fstream f("/tmp/eval", std::ios::trunc);
+    std::fstream f("/tmp/eval", std::ios::out);
 
+    if (!f.good()) {
+        isc_throw(isc::Unexpected, "Can't write /tmp/eval file");
+    }
     f << str;
     f.close();
 

+ 1 - 0
src/lib/eval/tests/Makefile.am

@@ -25,6 +25,7 @@ if HAVE_GTEST
 TESTS += libeval_unittests
 
 libeval_unittests_SOURCES  = token_unittest.cc main.cc
+libeval_unittests_SOURCES += context_unittest.cc
 libeval_unittests_CXXFLAGS = $(AM_CXXFLAGS)
 libeval_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 libeval_unittests_LDFLAGS  = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS) $(GTEST_LDFLAGS)

+ 36 - 0
src/lib/eval/tests/context_unittest.cc

@@ -0,0 +1,36 @@
+// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <config.h>
+#include <eval/token.h>
+#include <eval/eval_context.h>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc::dhcp;
+
+namespace {
+
+TEST(EvalContextTest, basic) {
+
+    EvalContext tmp;
+
+    EXPECT_NO_THROW(tmp.parseString("option[123] == \"MSFT\""));
+}
+
+
+};