option('resv_mem_size', type : 'string', value : '512M')
option('working_dir', type : 'string', value : '/tmp/')
option('log_dir', type : 'string', value : '/tmp')
-option('enable_test_mode', type : 'boolean', value : false)
+option('enable_test_mode', type : 'boolean', value : true)
c->log_dir[strlen(log_dir)] = '\x00';
}
- c->test_mode = test_mode;
+ if (test_mode != -1)
+ c->test_mode = test_mode;
}
/**
const char *resv_mem_size = iniparser_getstring(ini, "main:resv_mem_size", NULL);
const char *working_dir = iniparser_getstring(ini, "main:working_dir", NULL);
const char *log_dir = iniparser_getstring(ini, "main:log_dir", NULL);
- int test_mode = iniparser_getboolean(ini, "main:test_mode", DEFAULT_TEST_MODE);
+ int test_mode = iniparser_getboolean(ini, "main:test_mode", -1);
load_conf_each (resv_mem_size, working_dir, log_dir, test_mode, c);
}
const char *working_dir = getenv (ENV_WORKING_DIR);
const char *log_dir = getenv (ENV_LOG_DIR);
const char *test_mode_str = getenv (ENV_TEST_MODE);
- int test_mode = DEFAULT_TEST_MODE;
+ int test_mode = -1;
/* the below is iniparser's getboolean condition */
- if (test_mode_str && (test_mode_str[0] == '1'
- || test_mode_str[0] == 't' || test_mode_str[0] == 'T'
- || test_mode_str[0] == 'y' || test_mode_str[0] == 'Y'))
- test_mode = 1;
+ if (test_mode_str) {
+ test_mode = (test_mode_str[0] == '1'
+ || test_mode_str[0] == 't' || test_mode_str[0] == 'T'
+ || test_mode_str[0] == 'y' || test_mode_str[0] == 'Y');
+ }
load_conf_each (resv_mem_size, working_dir, log_dir, test_mode, c);
}
extern "C"
{
#include <ne-utils.h>
+ #include <ne-conf.h>
}
/**
}
ASSERT_EQ (i, num - 1);
ASSERT_EQ (test_ht.num, 0);
+ ASSERT_EQ (hash_table_destroy (&test_ht), 0);
+}
+
+/**
+ * @brief test functionality of load_conf (.ini and env)
+ */
+TEST (ne_core_utils_test, load_conf)
+{
+ FILE *fp = fopen ("dummy.ini", "w");
+ const char *ini_str = "[main]\n"
+ "resv_mem_size=128k\n"
+ "working_dir=/tmp/test_working\n"
+ "log_dir=/tmp/test_log\n"
+ "test_mode=n\n";
+
+ /** from .ini file */
+ ASSERT_NE (fp, nullptr);
+ ASSERT_EQ (fwrite (ini_str, strlen(ini_str), 1, fp), 1);
+ ASSERT_EQ (fclose (fp), 0);
+
+ ASSERT_EQ (load_conf ("dummy.ini"), 0);
+ ASSERT_EQ (conf->reserved_mem_size, (uint64_t) 128 * 1024);
+ ASSERT_STREQ (conf->working_dir, "/tmp/test_working");
+ ASSERT_STREQ (conf->log_dir, "/tmp/test_log");
+ ASSERT_EQ (conf->test_mode, 0);
+
+ /** from env */
+ ASSERT_EQ (setenv("NE_RESV_MEM_SIZE", "512G", 1), 0);
+ ASSERT_EQ (setenv("NE_WORKING_DIR", "/tmp/", 1), 0);
+ ASSERT_EQ (setenv("NE_LOG_DIR", "/tmp/", 1), 0);
+ ASSERT_EQ (setenv("NE_TEST_MODE", "YES", 1), 0);
+
+ ASSERT_EQ (load_conf (NULL), 0);
+ ASSERT_EQ (conf->reserved_mem_size, (uint64_t) 512 * 1024 * 1024 * 1024);
+ ASSERT_STREQ (conf->working_dir, "/tmp/");
+ ASSERT_STREQ (conf->log_dir, "/tmp/");
+ ASSERT_EQ (conf->test_mode, 1);
}
/**