89029841f337837bee108926fdb3d09def182f22
[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 = schema_get_xpaths(&xpaths);
41     if(xpaths_count < 0) {
42         log_error("schema_get_xpaths failed");
43         return NTS_ERR_FAILED;
44     }
45     else {
46         log_message(0, "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 schema_print_xpath()
54     for(int i = 0 ; i < xpaths_count; i++) {
55         int rc = schema_print_xpath(xpaths[i]);
56         if(rc != NTS_ERR_OK) {
57             log_error("error in schema_print_xpath");
58             return rc;
59         }
60     }
61
62     log_message(0, "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 = schema_populate();
72     if(rc != NTS_ERR_OK) {
73         log_error("error in schema_populate");
74         return rc;
75     }
76     
77     log_message(0, "schema_populate executed with "LOG_COLOR_BOLD_GREEN"success"LOG_COLOR_RESET"\n");
78
79     log_message(0, LOG_COLOR_BOLD_GREEN"ALL TESTS WENT GOOD!"LOG_COLOR_RESET"\n\n\n");
80
81     //switching back verbosity level
82     framework_arguments.verbosity_level = old_verbosity_level;
83
84     return NTS_ERR_OK;
85 }
86
87 int test_mode_run(void) {
88     assert_session();
89
90    
91     return NTS_ERR_OK;
92 }