Browse Source

[trac1057] fixed linker problem due to duplicate symbols from creator.h:
- use inline for the shared function
also removed some bad practices:
- remove unnamed namespace
- remove using [namespace] directives

In addition, make sure $(B10_CXXFLAGS) is used as part of CXXFLAGS.
Without this, warning flags could be unacceptably weakened.

JINMEI Tatuya 14 years ago
parent
commit
3bb777140c

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

@@ -1,5 +1,6 @@
 AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
 AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CXXFLAGS = $(B10_CXXFLAGS)
 
 TESTS =
 if HAVE_GTEST

+ 40 - 35
src/lib/acl/tests/creators.h

@@ -19,17 +19,16 @@
 #define CREATORS_H
 
 #include "logcheck.h"
+
+#include <cc/data.h>
 #include <acl/loader.h>
 #include <string>
 
-using isc::data::ConstElementPtr;
-using namespace std;
-using namespace boost;
-
-namespace {
-
 // Just for convenience, create JSON objects from JSON string
-ConstElementPtr el(const string& JSON) {
+// (Note that inline is absolutely necessary here, because it's defined in
+// a header file shared in multiple translation units)
+inline isc::data::ConstElementPtr
+el(const std::string& JSON) {
     return (isc::data::Element::fromJSON(JSON));
 }
 
@@ -37,35 +36,36 @@ ConstElementPtr el(const string& JSON) {
 // and data
 class NamedCheck : public Check<Log> {
 public:
-    NamedCheck(const string& name, ConstElementPtr data) :
+    NamedCheck(const std::string& name, isc::data::ConstElementPtr data) :
         name_(name),
         data_(data)
     {}
     virtual bool matches(const Log&) const { return (true); }
-    const string name_;
-    const ConstElementPtr data_;
+    const std::string name_;
+    const isc::data::ConstElementPtr data_;
 };
 
 // The creator of NamedCheck
 class NamedCreator : public Loader<Log>::CheckCreator {
 public:
-    NamedCreator(const string& name, bool abbreviatedList = true) :
+    NamedCreator(const std::string& name, bool abbreviatedList = true) :
         abbreviated_list_(abbreviatedList)
     {
         names_.push_back(name);
     }
-    NamedCreator(const vector<string>& names) :
+    NamedCreator(const std::vector<std::string>& names) :
         names_(names),
         abbreviated_list_(true)
     {}
-    vector<string> names() const {
+    std::vector<std::string> names() const {
         return (names_);
     }
-    shared_ptr<Check<Log> > create(const string& name, ConstElementPtr data,
-                                   const Loader<Log>&)
+    boost::shared_ptr<Check<Log> > create(const std::string& name,
+                                          isc::data::ConstElementPtr data,
+                                          const Loader<Log>&)
     {
         bool found(false);
-        for (vector<string>::const_iterator i(names_.begin());
+        for (std::vector<std::string>::const_iterator i(names_.begin());
              i != names_.end(); ++i) {
             if (*i == name) {
                 found = true;
@@ -74,13 +74,13 @@ public:
         }
         EXPECT_TRUE(found) << "Name " << name << " passed to creator which "
             "doesn't handle it.";
-        return (shared_ptr<Check<Log> >(new NamedCheck(name, data)));
+        return (boost::shared_ptr<Check<Log> >(new NamedCheck(name, data)));
     }
     bool allowListAbbreviation() const {
         return (abbreviated_list_);
     }
 private:
-    vector<string> names_;
+    std::vector<std::string> names_;
     const bool abbreviated_list_;
 };
 
@@ -90,13 +90,14 @@ class TestCreatorError {};
 // This will throw every time it should create something
 class ThrowCreator : public Loader<Log>::CheckCreator {
 public:
-    vector<string> names() const {
-        vector<string> result;
+    std::vector<std::string> names() const {
+        std::vector<std::string> result;
         result.push_back("throw");
         return (result);
     }
-    shared_ptr<Check<Log> > create(const string&, ConstElementPtr,
-                                   const Loader<Log>&)
+    boost::shared_ptr<Check<Log> > create(const std::string&,
+                                          isc::data::ConstElementPtr,
+                                          const Loader<Log>&)
     {
         throw TestCreatorError();
     }
@@ -113,22 +114,23 @@ public:
 // And creator for it
 class ThrowCheckCreator : public Loader<Log>::CheckCreator {
 public:
-    vector<string> names() const {
-        vector<string> result;
+    std::vector<std::string> names() const {
+        std::vector<std::string> result;
         result.push_back("throwcheck");
         return (result);
     }
-    shared_ptr<Check<Log> > create(const string&, ConstElementPtr,
-                                   const Loader<Log>&)
+    boost::shared_ptr<Check<Log> > create(const std::string&,
+                                          isc::data::ConstElementPtr,
+                                          const Loader<Log>&)
     {
-        return (shared_ptr<Check<Log> >(new ThrowCheck()));
+        return (boost::shared_ptr<Check<Log> >(new ThrowCheck()));
     }
 };
 
 class LogCreator : public Loader<Log>::CheckCreator {
 public:
-    vector<string> names() const {
-        vector<string> result;
+    std::vector<std::string> names() const {
+        std::vector<std::string> result;
         result.push_back("logcheck");
         return (result);
     }
@@ -137,18 +139,21 @@ public:
      * logging cell used, the second is result of the check. No error checking
      * is done, if there's bug in the test, it will throw TypeError for us.
      */
-    shared_ptr<Check<Log> > create(const string&, ConstElementPtr definition,
-                                   const Loader<Log>&)
+    boost::shared_ptr<Check<Log> > create(const std::string&,
+                                          isc::data::ConstElementPtr definition,
+                                          const Loader<Log>&)
     {
-        vector<ConstElementPtr> list(definition->listValue());
+        std::vector<isc::data::ConstElementPtr> list(definition->listValue());
         int logpos(list[0]->intValue());
         bool accept(list[1]->boolValue());
-        return (shared_ptr<ConstCheck>(new ConstCheck(accept, logpos)));
+        return (boost::shared_ptr<ConstCheck>(new ConstCheck(accept, logpos)));
     }
     // We take a list, so don't interpret it for us
     virtual bool allowListAbbreviation() const { return (false); }
 };
 
-}
-
 #endif
+
+// Local Variables:
+// mode: c++
+// End:

+ 1 - 0
src/lib/acl/tests/loader_test.cc

@@ -19,6 +19,7 @@
 
 using namespace std;
 using namespace boost;
+using isc::data::ConstElementPtr;
 
 namespace {
 

+ 3 - 0
src/lib/acl/tests/logic_check_test.cc

@@ -15,7 +15,10 @@
 #include "creators.h"
 #include <acl/logic_check.h>
 #include <typeinfo>
+#include <boost/shared_ptr.hpp> // for static_pointer_cast
 
+using namespace std;
+using namespace boost;
 using namespace isc::acl;
 
 namespace {