Sanitize test data collection 02/235202/7
authorZofia Abramowska <z.abramowska@samsung.com>
Tue, 2 Jun 2020 14:41:10 +0000 (16:41 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Fri, 10 Jul 2020 13:15:20 +0000 (15:15 +0200)
* add template generation for numeric data
* remove redundant static specifier

Change-Id: I6f64988d98c633e55d027bb5c9f5bf0b8b2597a0

test/common/protocols/TestDataCollection.h

index a5310d6fe7ca938441567255aba0317c0230bd87..81a260a995723faa12ad70d016ab7f3e6a99ad26 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
 #define TEST_COMMON_PROTOCOLS_TESTDATACOLLECTION_H_
 
 #include <cstdint>
+#include <ctime>
+#include <limits>
+#include <vector>
 
+#include <types/Agent.h>
+#include <types/Policy.h>
 #include <types/PolicyBucketId.h>
 #include <types/PolicyKey.h>
 #include <types/PolicyResult.h>
 #include <types/ProtocolFields.h>
 
 namespace {
+
 namespace TestDataCollection {
 
+template <typename T,
+          T min_ = std::numeric_limits<T>::min(),
+          T max_ = std::numeric_limits<T>::max()
+          >
+struct NumericDataCollection {
+    static constexpr T min = min_;
+    static constexpr T max = max_;
+    static constexpr T min_1 = min_ + 1;
+    static constexpr T min_2 = min_ + 2;
+    static constexpr T max_1 = max_ - 1;
+    static constexpr T max_2 = max_ - 2;
+    static constexpr T mid = (min_ + max_) / 2;
+    static constexpr T all[] = {
+        min, max, min_1, min_2, max_1, max_2, mid
+    };
+};
+
+typedef NumericDataCollection<Cynara::ProtocolFrameSequenceNumber> SN;
+
 typedef Cynara::PolicyKeyFeature PKF;
 
 namespace Keys {
@@ -66,21 +91,6 @@ const Cynara::PolicyKey all[] = {
 
 } /* namespace Keys */
 
-namespace SN {
-
-const Cynara::ProtocolFrameSequenceNumber min(0);
-const Cynara::ProtocolFrameSequenceNumber min_1(min + 1);
-const Cynara::ProtocolFrameSequenceNumber min_2(min + 2);
-const Cynara::ProtocolFrameSequenceNumber max(UINT16_MAX);
-const Cynara::ProtocolFrameSequenceNumber max_1(max - 1);
-const Cynara::ProtocolFrameSequenceNumber max_2(max - 2);
-const Cynara::ProtocolFrameSequenceNumber mid((min + max) / 2);
-const Cynara::ProtocolFrameSequenceNumber all[] = {
-    min, min_1, min_2, max, max_1, max_2, mid
-};
-
-} /* namespace SN */
-
 namespace Buckets {
 
 const Cynara::PolicyBucketId empty("");
@@ -92,11 +102,16 @@ const Cynara::PolicyBucketId all[] = {
 } /* namespace Buckets */
 
 namespace Types {
-    static const Cynara::PolicyType allow(Cynara::PredefinedPolicyType::ALLOW);
-    static const Cynara::PolicyType deny(Cynara::PredefinedPolicyType::DENY);
-    static const Cynara::PolicyType bucket(Cynara::PredefinedPolicyType::BUCKET);
-    static const Cynara::PolicyType none(Cynara::PredefinedPolicyType::NONE);
-    static const Cynara::PolicyType plugin_type(100);
+
+const Cynara::PolicyType allow(Cynara::PredefinedPolicyType::ALLOW);
+const Cynara::PolicyType deny(Cynara::PredefinedPolicyType::DENY);
+const Cynara::PolicyType bucket(Cynara::PredefinedPolicyType::BUCKET);
+const Cynara::PolicyType none(Cynara::PredefinedPolicyType::NONE);
+const Cynara::PolicyType plugin_type(100);
+const Cynara::PolicyType all[] = {
+    allow, deny, bucket, none, plugin_type
+};
+
 } /* namespace Types */
 
 namespace Results {
@@ -113,6 +128,7 @@ const Cynara::PolicyResult all[] = {
 };
 
 } /* namespace Results */
+
 } /* namespace TestDataCollection */
 } /* namespace anonymous */