Put some .cpp-local entities in anon ns 90/267590/2
authorKonrad Lipinski <k.lipinski2@samsung.com>
Tue, 7 Dec 2021 12:54:40 +0000 (13:54 +0100)
committerKonrad Lipinski <k.lipinski2@samsung.com>
Tue, 7 Dec 2021 13:17:37 +0000 (14:17 +0100)
This fixes at least one ODR violtation (FakeStreamForBucketId) which was
defined twice, in test/storage/serializer/{deserialize,serializer}.cpp.
Two unit tests would fail in some environments as a result, particularly
StorageSerializerFixture.dumpBucketsPositive, due to dynamic_cast
failing within gtest (the one from serializer.cpp was being cast to the
one from deserializer.cpp).

Change-Id: Ie0dc0191b4e45d032b68b0df9bfcdf81fca8678f

15 files changed:
src/cyad/CommandlineParser/HumanReadableParser.cpp
src/helpers/creds-sd-bus/creds-sd-bus-inner.cpp
src/service/main/main.cpp
test/common/containers/test_binary_queue.cpp
test/common/error/safestrerror.cpp
test/common/exceptions/trycatch.cpp
test/common/protocols/ProtocolSerialization.cpp
test/common/types/policybucket.cpp
test/credsCommons/parser/Parser.cpp
test/storage/performance/bucket.cpp
test/storage/serializer/bucket_load.cpp
test/storage/serializer/deserialize.cpp
test/storage/serializer/dump_load.cpp
test/storage/serializer/serialize.cpp
test/tests.cpp

index d71a64f0f044e2f17da81c382b082f995738eb8c..c4edd84a6c2d96130b216b3e82b7d5786c19b477 100644 (file)
@@ -38,9 +38,11 @@ namespace Cynara {
 
 namespace HumanReadableParser {
 
+namespace {
 std::unordered_set<std::string> yeses = {
     "y", "1", "yes", "true", "on", "yeah", "yep", "of course", "sure thing"
 };
+} // namespace
 
 bool isYes(const std::string &value) {
     std::string lower_value(value);
index 80cc7ce4e8ffcab9f6d382f2ed97a5e77957e77e..24204634bc7f08ff2a852dc63b0958768a2f41fd 100644 (file)
@@ -37,6 +37,7 @@
 
 #include <creds-sd-bus-inner.h>
 
+namespace {
 int copyStr(char **destStr, const std::string &str) {
     if (!destStr) {
         return CYNARA_API_INVALID_PARAM;
@@ -49,6 +50,7 @@ int copyStr(char **destStr, const std::string &str) {
     *destStr = destTmp;
     return CYNARA_API_SUCCESS;
 }
+} // namespace
 
 int getPid(sd_bus *bus, const char *name, pid_t *pid) {
     return Cynara::tryCatch([&bus, &name, &pid]() {
index 04884c1e5ee5ea64a6bc41b33ff5f7d96bd660d5..57b45a59a992cb42fd4013b1fd3faab035e3d06f 100644 (file)
@@ -46,6 +46,7 @@
 #include "CmdlineParser.h"
 #include "Cynara.h"
 
+namespace {
 void daemonize(void) {
     switch (fork()) {
         case -1:
@@ -88,6 +89,7 @@ void daemonize(void) {
             close(fd);
     }
 }
+} // namespace
 
 int main(int argc, char **argv) {
     try {
index cd8931d6139f2c89b31e40e69119d5defbcef88f..6d3d3eacfd86eb601ade4c5b8f820b6bf54621e5 100644 (file)
@@ -23,6 +23,7 @@
 #include <dpl/binary_queue.h>
 RUNNER_TEST_GROUP_INIT(DPL)
 
+namespace {
 inline std::string BinaryQueueToString(const DPL::BinaryQueue &queue)
 {
     char *buffer = new char[queue.Size()];
@@ -31,6 +32,7 @@ inline std::string BinaryQueueToString(const DPL::BinaryQueue &queue)
     delete[] buffer;
     return result;
 }
+} // namespace
 
 /*
 Name: BinaryQueue_InitialEmpty
@@ -385,6 +387,7 @@ RUNNER_TEST(BinaryQueue_AppendMoveTo)
     RUNNER_ASSERT(BinaryQueueToString(copy) == "abcdef");
 }
 
+namespace {
 class Visitor :
     public DPL::BinaryQueue::BucketVisitor
 {
@@ -417,6 +420,7 @@ class Visitor :
         ++m_index;
     }
 };
+} // namespace
 
 /*
 Name: BinaryQueue_Visitor
index 64692eb7a1d6e2f45dc5e99499a67645b3715fb7..f456941ae838ab0cf3567ab07e9d391a509f47e2 100644 (file)
@@ -68,15 +68,15 @@ std::vector<std::string> errnosToStrings(const int errnos[], int errnum) {
     return errnosStrings;
 }
 
-} // namespace anonymous
-
-using namespace Cynara;
-
 struct Status {
     bool success = false;
     std::string errorMsg;
 };
 
+} // namespace anonymous
+
+using namespace Cynara;
+
 TEST(SafeStrError, knownErrnosPositive)
 {
     const std::vector<std::string> KNOWN_ERRNOS_STRINGS =
index f6c691e9f793fddd296125074ae95865e63e4ee5..788a8bc5ede06aa9171f91d92fd51ed9339dbf25 100644 (file)
@@ -83,8 +83,6 @@ const std::string SOME_BUCKET = "someBucket";
 const std::string SOME_LINE = "some line";
 const std::string SOME_FILE = "some.file";
 
-} // namespace anonymous
-
 class DerivedException : public Cynara::Exception {
 public:
     DerivedException() {}
@@ -95,6 +93,8 @@ public:
     };
 };
 
+} // namespace anonymous
+
 TEST(TryCatch, forcedUnwindNegative)
 {
     pthread_t id;
index b906ae70cd7ec6b98176db5bb9e8b40eda74733d..6eb70f3f5f37916da37e04db560d387e945dd72b 100644 (file)
@@ -35,6 +35,7 @@
 #include <common/protocol/ProtocolSerialization.h>
 #include <cynara-limits.h>
 
+namespace {
 class FakeIStream : public Cynara::IStream {
 public:
     MOCK_METHOD2(read, void(size_t, void*));
@@ -46,6 +47,7 @@ ACTION_P(AssignUInt16, param) {
     memcpy(arg1, &hparam, sizeof(hparam));
 }
 ACTION_P(AssignString, param) { strcpy(static_cast<char*>(arg1), param); }
+} // namespace
 
 TEST(Serialization, maxStringPositive) {
     using ::testing::_;
index cf5a1f83bb78131fad8e2fd01ffe7cbcc3d149de..da77f3b0de96c3f643a851b0b6bc6b9b26f151e8 100644 (file)
@@ -41,6 +41,7 @@
 
 using namespace Cynara;
 
+namespace {
 class PolicyBucketFixture : public ::testing::Test {
 public:
     virtual ~PolicyBucketFixture() {}
@@ -73,6 +74,7 @@ protected:
         "badid\n", " badid", "bad id", "badid "
     };
 };
+} // namespace
 
 TEST_F(PolicyBucketFixture, FilteredPositive) {
     using ::testing::UnorderedElementsAre;
index 5fe7ec1a88ea5c82a1b761d7c5e85c393911b786..bbbc196f8c75127bfa2edee384a00404f60fedd5 100644 (file)
@@ -54,11 +54,13 @@ using ::testing::Throw;
 
 /*** Test for getKeyAndValue() ***/
 
+namespace {
 struct getKeyAndValueTestEntry {
     std::string testString;
     std::string key;
     std::string value;
 };
+} // namespace
 
 TEST(Parser, getKeyAndValuePositive) {
     const std::vector<struct getKeyAndValueTestEntry>  getKeyAndValueTestEntries = {
index f2cb99d455fee8013a47d1ada4ebf3b3fb68bb4c..719f8fd3f003cd94e9048d269e4f996b1af36db5 100644 (file)
@@ -43,6 +43,7 @@
 
 using namespace Cynara;
 
+namespace {
 class PolicyKeyGenerator {
 public:
     typedef std::vector<std::string> Features;
@@ -80,6 +81,7 @@ private:
     Features m_users;
     Features m_privileges;
 };
+} // namespace
 
 TEST(Performance, bucketFiltered100000Positive) {
     using std::chrono::microseconds;
index 87f28eca3f3b07627c08cb406ff4c028bab4cfdc..358be11937193c0614e7d9348a510bcb057f124d 100644 (file)
@@ -41,6 +41,7 @@
 
 using namespace Cynara;
 
+namespace {
 MATCHER_P(PolicyAtPtrEq, policy, "") {
     return std::tie(policy->key(), policy->result())
         == std::tie(arg->key(), arg->result());
@@ -69,6 +70,7 @@ public:
         }
     }
 };
+} // namespace
 
 TEST_F(BucketDeserializerFixture, loadEmptyPositive) {
     using ::testing::IsEmpty;
index 12ba4faa1960c0061d1de0472c74e92ea28776ca..5e7c7b3001ab51bc697c852c87cd8b4a83e12f46 100644 (file)
@@ -37,6 +37,7 @@
 #include <storage/StorageDeserializer.h>
 #include <types/PolicyBucket.h>
 
+namespace {
 MATCHER_P(PolicyBucketIdPolicyEq, expected, "") {
     auto bucket1 = expected.second;
     auto bucket2 = arg.second;
@@ -71,6 +72,7 @@ public:
             return emptyBucketStream();
         };
 };
+} // namespace
 
 using namespace Cynara;
 
index 8e37dc7be77d2e7591af11c596bbf7831fc3fe31..9233ce07fb92c19f7d632eba12deaad70fa51946 100644 (file)
 
 using namespace Cynara;
 
+namespace {
 // TODO: Move to helpers or other .h
 MATCHER_P(PolicyAtPtrEq, policy, "") {
     return std::tie(policy->key(), policy->result())
         == std::tie(arg->key(), arg->result());
 }
+} // namespace
 
 // Test if dumping and loading yields the same result
 TEST(DumpLoad, BucketPositive) {
index d4d0e01fc0abd4254eb697c009f73d0815e56354..0e7bc41f578d2206a97b0d6df1cc524a5f63ff8d 100644 (file)
@@ -40,6 +40,7 @@
 #include <storage/StorageSerializer.h>
 #include <types/PolicyBucketId.h>
 
+namespace {
 class FakeStreamForBucketId {
 public:
     typedef std::shared_ptr<Cynara::StorageSerializer<std::stringstream> >
@@ -69,6 +70,7 @@ public:
     Cynara::Buckets buckets;
     FakeStreamForBucketId fakeStreamOpener;
 };
+} // namespace
 
 using namespace Cynara;
 
index c45ce8103e05d42cc905490e2933c9d1152d2615..38b19c7edf2a354cc6d04ae072a422fe9dfba2ff 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "TestEventListenerProxy.h"
 
+namespace {
 class PropertyAwarePrettyUnitTestResultPrinter : public Cynara::TestEventListenerProxy {
     using Cynara::TestEventListenerProxy::TestEventListenerProxy;
 
@@ -44,6 +45,7 @@ class PropertyAwarePrettyUnitTestResultPrinter : public Cynara::TestEventListene
         originalListener()->OnTestEnd(testInfo);
     }
 };
+} // namespace
 
 int main(int argc, char** argv) {
     // Disables elapsed time by default.