52ed5ff1e017eac4ee44af449bc81708927df96a
[sim/o1-interface.git] / ntsimulator / ntsim-ng / core / test.c
1 /*************************************************************************
2 *
3 * Copyright 2020 highstreet technologies GmbH and others
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 ***************************************************************************/
17
18 #define _GNU_SOURCE
19
20 #include "test.h"
21 #include "utils/log_utils.h"
22 #include "utils/rand_utils.h"
23 #include "utils/type_utils.h"
24 #include "utils/sys_utils.h"
25 #include <stdio.h>
26 #include <assert.h>
27
28 #include <libyang/libyang.h>
29 #include "core/session.h"
30 #include "core/framework.h"
31 #include "core/docker.h"
32
33 #include "core/datastore/schema.h"
34 #include "core/datastore/populate.h"
35
36
37 int exhaustive_test_run(void) {
38     //first get all xpaths
39     char **xpaths = 0;
40     int xpaths_count = datastore_schema_get_xpaths(&xpaths);
41     if(xpaths_count < 0) {
42         log_error("datastore_schema_get_xpaths failed\n");
43         return NTS_ERR_FAILED;
44     }
45     else {
46         log_add_verbose(0, "datastore_schema_get_xpaths executed with "LOG_COLOR_BOLD_GREEN"success"LOG_COLOR_RESET" (%d)\n", xpaths_count);
47     }
48
49     //switching verbosity level to 0 so we don't see logs
50     int old_verbosity_level = framework_arguments.verbosity_level;
51     framework_arguments.verbosity_level = 0;
52
53     //testing datastore_schema_print_xpath()
54     for(int i = 0 ; i < xpaths_count; i++) {
55         int rc = datastore_schema_print_xpath(xpaths[i]);
56         if(rc != NTS_ERR_OK) {
57             log_error("error in datastore_schema_print_xpath\n");
58             return rc;
59         }
60     }
61
62     log_add_verbose(0, "datastore_schema_print_xpath executed with "LOG_COLOR_BOLD_GREEN"success"LOG_COLOR_RESET" for all paths\n");
63
64     //freeing paths
65     for(int i = 0; i < xpaths_count; i++) {
66         free(xpaths[i]);
67     }
68     free(xpaths);
69
70     //testing schema_populate
71     int rc = datastore_populate(1);
72     if(rc != NTS_ERR_OK) {
73         log_error("error in datastore_populate\n");
74         return rc;
75     }
76     
77     log_add_verbose(0, "datastore_populate executed with "LOG_COLOR_BOLD_GREEN"success"LOG_COLOR_RESET"\n");
78     log_add_verbose(0, LOG_COLOR_BOLD_GREEN"ALL TESTS WENT GOOD!"LOG_COLOR_RESET"\n\n\n");
79
80     //switching back verbosity level
81     framework_arguments.verbosity_level = old_verbosity_level;
82
83     return NTS_ERR_OK;
84 }
85
86 int test_mode_run(void) {
87     assert_session();
88
89    
90     return NTS_ERR_OK;
91 }