test : apply CPP style log 29/238329/3
authorKichan Kwon <k_c.kwon@samsung.com>
Mon, 13 Jul 2020 01:11:51 +0000 (10:11 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Thu, 13 Aug 2020 08:17:57 +0000 (17:17 +0900)
Change-Id: I6b009479663a9ba89909e3092bd28f5898615623
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
test/init_db/feature.cpp
test/init_db/system_info_init_db_test.cpp
test/init_db/system_info_init_db_test.h
test/init_db/tester.cpp
test/init_db/util.cpp

index b5f81b7..3a35dd0 100644 (file)
@@ -28,7 +28,7 @@ BoolFeature::BoolFeature(std::string k, std::string v) : Feature(k)
        else if (!v.compare(STRBOOL_FALSE))
                value = false;
        else {
-               LOG("Invalid value : key(%s), value(%s)", k.c_str(), v.c_str());
+               LOG << "Invalid value : key(" << k << "), value(" << v << ")" << ENDL;
                value = false;
        }
 }
@@ -45,7 +45,7 @@ int BoolFeature::modifyValue(void)
                value = true;
                break;
        default:
-               LOG("Invalid modType");
+               LOG << "Invalid modType" << ENDL;
                return EINVAL;
        }
 
@@ -59,15 +59,15 @@ int BoolFeature::verifyValue(void)
 
        ret = system_info_get_platform_bool(key.c_str(), &output);
        if (ret != SYSTEM_INFO_ERROR_NONE) {
-               LOG("system_info_get_platform_bool failed (%d)", ret);
+               LOG << "system_info_get_platform_bool failed : " << ret << ENDL;
                return ret;
        }
 
        if (value != output) {
-               LOG("Failed to verify value : key(%s), value(%s), expected(%s)",
-                               key.c_str(),
-                               output ? STRBOOL_TRUE : STRBOOL_FALSE,
-                               value ? STRBOOL_TRUE : STRBOOL_FALSE);
+               LOG << "Failed to verify value : key(" << key
+                       << "), value(" << (output ? STRBOOL_TRUE : STRBOOL_FALSE)
+                       << "), expected(" << (value ? STRBOOL_TRUE : STRBOOL_FALSE)
+                       << ")" << ENDL;
                return -1;
        }
 
@@ -96,7 +96,7 @@ int IntFeature::modifyValue(void)
                value /= 128;
                break;
        default:
-               LOG("Invalid modType");
+               LOG << "Invalid modType" << ENDL;
                break;
        }
 
@@ -110,13 +110,14 @@ int IntFeature::verifyValue(void)
 
        ret = system_info_get_platform_int(key.c_str(), &output);
        if (ret != SYSTEM_INFO_ERROR_NONE) {
-               LOG("system_info_get_platform_int failed (%d)", ret);
+               LOG << "system_info_get_platform_int failed : " << ret << ENDL;
                return ret;
        }
 
        if (value != output) {
-               LOG("Failed to verify value : key(%s), value(%d), expected(%d)",
-                               key.c_str(), output, value);
+               LOG << "Failed to verify value : key(" << key
+                       << "), value(" << output
+                       << "), expected(" << value << ")" << ENDL;
                return -1;
        }
 
@@ -144,7 +145,7 @@ int DoubleFeature::modifyValue(void)
                value /= 128.0;
                break;
        default:
-               LOG("Invalid modType");
+               LOG << "Invalid modType" << ENDL;
                break;
        }
 
@@ -161,13 +162,15 @@ int DoubleFeature::verifyValue(void)
 
        ret = system_info_get_platform_double(key.c_str(), &output);
        if (ret != SYSTEM_INFO_ERROR_NONE) {
-               LOG("system_info_get_platform_double failed (%d)", ret);
+               LOG << "system_info_get_platform_double failed : " << ret << ENDL;
                return ret;
        }
 
        if (value != output) {
-               LOG("Failed to verify value : key(%s), value(%.16lf), expected(%.16lf)",
-                               key.c_str(), output, value);
+               LOG << std::fixed << std::setprecision(15)
+                       << "Failed to verify value : key(" << key
+                       << "), value(" << output
+                       << "), expected(" << value << ")" << ENDL;
                return -1;
        }
 
@@ -193,7 +196,7 @@ int StringFeature::modifyValue(void)
                value.resize(std::max(value.length() / 2, (size_t)1));
                break;
        default:
-               LOG("Invalid modType");
+               LOG << "Invalid modType" << ENDL;
                break;
        }
 
@@ -207,13 +210,14 @@ int StringFeature::verifyValue(void)
 
        ret = system_info_get_platform_string(key.c_str(), &output);
        if (ret != SYSTEM_INFO_ERROR_NONE) {
-               LOG("system_info_get_platform_string failed (%d)", ret);
+               LOG << "system_info_get_platform_string failed : " << ret << ENDL;
                return ret;
        }
 
        if (value.compare(output)) {
-               LOG("Failed to verify value : key(%s), value(%s), expected(%s)",
-                               key.c_str(), output, value.c_str());
+               LOG << "Failed to verify value : key(" << key
+                       << "), value(" << output
+                       << "), expected(" << value << ")" << ENDL;
                return -1;
        }
 
index 7d4bd4a..f64b188 100644 (file)
@@ -20,7 +20,7 @@ static int initialize(void)
        if (access(SYSTEM_INFO_DB_RO_PATH, F_OK) == 0) {
                ret = util.forkAndExec("mv", SYSTEM_INFO_DB_RO_PATH, BACKUP_DB_RO_PATH, nullptr);
                if (ret != SUCCEED) {
-                       LOG("Failed to move original RO DB (%d)", ret);
+                       LOG << "Failed to move original RO DB : " << ret << ENDL;
                        return ret;
                }
        }
@@ -29,7 +29,7 @@ static int initialize(void)
        if (access(SYSTEM_INFO_DB_RW_PATH, F_OK) == 0) {
                ret = util.forkAndExec("mv", SYSTEM_INFO_DB_RW_PATH, BACKUP_DB_RW_PATH, nullptr);
                if (ret != SUCCEED) {
-                       LOG("Failed to move original RW DB (%d)", ret);
+                       LOG << "Failed to move original RW DB : " << ret << ENDL;
                        return ret;
                }
        }
@@ -37,7 +37,7 @@ static int initialize(void)
        // Read model-config
        ret = util.readModelConfig();
        if (ret != SUCCEED) {
-               LOG("Failed to read model-config (%d)", ret);
+               LOG << "Failed to read model-config : " << ret << ENDL;
                return ret;
        }
 
@@ -59,7 +59,7 @@ static void finalize(void)
        if (access(SYSTEM_INFO_DB_RW_PATH, F_OK) == 0) {
                ret = util.forkAndExec("rm", "-rf", SYSTEM_INFO_DB_RW_PATH, nullptr);
                if (ret != SUCCEED) {
-                       LOG("Failed to remove RW DB (%d)", ret);
+                       LOG << "Failed to remove RW DB : " << ret << ENDL;
                        goto handle_ro_db;
                }
        }
@@ -68,7 +68,7 @@ static void finalize(void)
        if (access(BACKUP_DB_RW_PATH, F_OK) == 0) {
                ret = util.forkAndExec("mv", BACKUP_DB_RW_PATH, SYSTEM_INFO_DB_RW_PATH, nullptr);
                if (ret != SUCCEED)
-                       LOG("Failed to move original RW DB (%d)", ret);
+                       LOG << "Failed to move original RW DB : " << ret << ENDL;
        }
 
 handle_ro_db:
@@ -76,7 +76,7 @@ handle_ro_db:
        if (access(SYSTEM_INFO_DB_RO_PATH, F_OK) == 0) {
                ret = util.forkAndExec("rm", "-rf", SYSTEM_INFO_DB_RO_PATH, nullptr);
                if (ret != SUCCEED) {
-                       LOG("Failed to remove RO DB (%d)", ret);
+                       LOG << "Failed to remove RO DB : " << ret << ENDL;
                        return;
                }
        }
@@ -85,7 +85,7 @@ handle_ro_db:
        if (access(BACKUP_DB_RO_PATH, F_OK) == 0) {
                ret = util.forkAndExec("mv", BACKUP_DB_RO_PATH, SYSTEM_INFO_DB_RO_PATH, nullptr);
                if (ret != SUCCEED)
-                       LOG("Failed to move original RO DB (%d)", ret);
+                       LOG << "Failed to move original RO DB : "<< ret << ENDL;
        }
 }
 
@@ -93,11 +93,11 @@ int main(int argc, char *argv[])
 {
        int ret;
 
-       LOG("========== Start system_info_init_db test ==========\n");
+       LOG << "========== Start system_info_init_db test ==========" << ENDL << ENDL;
 
        ret = initialize();
        if (ret != SUCCEED) {
-               LOG("Failed to initialize (%d)", ret);
+               LOG << "Failed to initialize : " << ret << ENDL;
                finalize();
                return ret;
        }
@@ -117,6 +117,6 @@ int main(int argc, char *argv[])
 
        finalize();
 
-       LOG("========== End system_info_init_db test ==========");
+       LOG << "========== End system_info_init_db test ==========" << ENDL;
        return 0;
 }
index 5d45018..41e1fc1 100644 (file)
@@ -1,11 +1,14 @@
 #ifndef __SYSTEM_INFO_INIT_DB_TEST_H__
 #define __SYSTEM_INFO_INIT_DB_TEST_H__
 
+#include <iostream>
+
 #define INIT_DB "system_info_init_db"
 
 #define SUCCEED 0
 
-#define LOG(fmt, arg...) printf(fmt "\n", ##arg)
+#define LOG std::cout
+#define ENDL std::endl
 
 #define BACKUP_DB_RO_PATH SYSTEM_INFO_DB_RO_PATH "_backup"
 #define BACKUP_DB_RW_PATH SYSTEM_INFO_DB_RW_PATH "_backup"
index 0a16659..c0d2a4c 100644 (file)
@@ -9,12 +9,16 @@ void Tester::test(void)
 {
        int ret;
 
-       LOG("[%s] Start", name.c_str());
+       LOG << "[" << name << "] Start" << ENDL;
 
        ret = run();
 
-       LOG("[%s] Result : %d(%s)\n", name.c_str(), ret,
-                       ret == SUCCEED ? "\x1b[32mPASSED\x1b[0m" : "\x1b[31mFAILED\x1b[0m");
+       LOG << "[" << name << "] Result = ";
+       if (ret == SUCCEED)
+               LOG << "\x1b[32mPASSED\x1b[0m";
+       else
+               LOG << "\x1b[31mFAILED\x1b[0m" << " : " << ret;
+       LOG << ENDL;
 }
 
 /********** CreateDB **********/
@@ -83,7 +87,7 @@ int InsertKey::run(void)
                        feature = new StringFeature(key, value);
                        break;
                default:
-                       LOG("Invalid dice value (%d)", dice);
+                       LOG << "Invalid dice value : " << dice << ENDL;
                        return EIO;
                }
 
@@ -91,7 +95,7 @@ int InsertKey::run(void)
 
                ret = util.updateDB(key, type, value);
                if (ret != SUCCEED) {
-                       LOG("Failed to insert key(%d)", ret);
+                       LOG << "Failed to insert key : " << ret << ENDL;
                        return ret;
                }
        }
@@ -108,7 +112,7 @@ int ModifyValue::run(void)
        for (auto feature : featureList) {
                ret = feature->modifyValue();
                if (ret != SUCCEED) {
-                       LOG("Failed to modify value (%d)", ret);
+                       LOG << "Failed to modify value : " << ret << ENDL;
                        return ret;
                }
        }
@@ -125,7 +129,7 @@ int VerifyValue::run(void)
        for (auto feature : featureList) {
                ret = feature->verifyValue();
                if (ret != SUCCEED) {
-                       LOG("Failed to verify value (%d)", ret);
+                       LOG << "Failed to verify value : " << ret << ENDL;
                        return ret;
                }
        }
index 0fde55e..5fe0d94 100644 (file)
@@ -24,7 +24,7 @@ int Util::forkAndExec(const char *argv, ...)
        pid = fork();
        switch (pid) {
        case -1:
-               LOG("fork failed");
+               LOG << "fork failed" << ENDL;
                return EIO;
        case 0:
                // Execute program
@@ -38,7 +38,7 @@ int Util::forkAndExec(const char *argv, ...)
 
                ret = execvp(arr[0], (char * const *)arr);
                if (ret == -1) {
-                       LOG("execv for %s failed (%d)", arr[0], errno);
+                       LOG << "execv for " << arr[0] << " failed : " << errno << ENDL;
                        ret = errno;
                } else
                        ret = SUCCEED;
@@ -47,7 +47,7 @@ int Util::forkAndExec(const char *argv, ...)
        default:
                // Wait until child is terminated
                if (wait(&status) == -1) {
-                       LOG("wait failed (%d)", errno);
+                       LOG << "wait failed : " << errno << ENDL;
                        return errno;
                }
                if (WIFEXITED(status) && WEXITSTATUS(status) == SUCCEED)
@@ -93,19 +93,19 @@ int Util::readModelConfig(void)
        // Read xml file
        doc = xmlParseFile(MODEL_CONFIG_RO_PATH);
        if (!doc) {
-               LOG("xmlParseFile failed");
+               LOG << "xmlParseFile failed" << ENDL;
                return ENOENT;
        }
 
        nodeRoot = xmlDocGetRootElement(doc);
        if (!nodeRoot) {
-               LOG("xmlDocGetRootElement failed");
+               LOG << "xmlDocGetRootElement failed" << ENDL;
                ret = ENOENT;
                goto clean;
        }
 
        if (xmlStrcmp(nodeRoot->name, (const xmlChar *)"model-config")) {
-               LOG("Failed to find model-config tag");
+               LOG << "Failed to find model-config tag" << ENDL;
                ret = ENOENT;
                goto clean;
        }
@@ -120,7 +120,7 @@ int Util::readModelConfig(void)
        }
 
        if (!nodeKey) {
-               LOG("Failed to find platform tag");
+               LOG << "Failed to find platform tag" << ENDL;
                ret = ENOENT;
                goto clean;
        }
@@ -137,8 +137,9 @@ int Util::readModelConfig(void)
                        if (!propName && !propType && !propValue)
                                continue;
 
-                       LOG("Invalid feature : name(%s), type(%s), value(%s)",
-                                       (char *)propName, (char *)propType, (char *)propValue);
+                       LOG << "Invalid feature : name(" << propName
+                               << "), type(" << propType
+                               << "), value(" << propValue << ")" << ENDL;
                        ret = EIO;
                        goto clean;
                }
@@ -160,7 +161,7 @@ int Util::readModelConfig(void)
                        feature = new StringFeature(name, value);
                        numStringKey++;
                } else {
-                       LOG("Invalid type : key(%s), type(%s)", name.c_str(), type.c_str());
+                       LOG << "Invalid type : key(" << name << "), type(" << type << ")" << ENDL;
                        ret = EINVAL;
                        goto clean;
                }
@@ -172,9 +173,13 @@ int Util::readModelConfig(void)
                xmlFree(propName);
        }
 
-       LOG("Number of model-config platform key : Bool(%d), Int(%d), Double(%d), String(%d), Total(%d)\n",
-                       numBoolKey, numIntKey, numDoubleKey, numStringKey,
-                       numBoolKey + numIntKey + numDoubleKey + numStringKey);
+       LOG << "Number of model-config platform key : "
+               << "Bool(" << numBoolKey
+               << "), Int(" << numIntKey
+               << "), Double(" << numDoubleKey
+               << "), String(" << numStringKey
+               << "), Total(" << numBoolKey + numIntKey + numDoubleKey + numStringKey << ")"
+               << ENDL << ENDL;
        ret = SUCCEED;
 
 clean: