summaryrefslogtreecommitdiff
path: root/unittest/beluga-adaptor_setting.cpp
blob: 083d39ad5e560d53692850d31a4ef3b8c470d5e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtest/gtest.h>
#include <unistd.h>

#include <sys/stat.h>
#include <sys/types.h>
#include <pthread.h>

#include "sa_common.h"
#include "adaptor_api.h"
#include "adaptor_setting.h"
#include "setup_system.h"
#include "adaptor_util.h"
#include "parse_file.h"
#include "json_util.h"


using ::testing::InitGoogleTest;

TEST(beluga_adaptor_setting, beluga_adaptor_setup_user_certificates){    
    int ret = 0;

    _D("[UNIT_TEST] setup_user_certificates ~~~~~");

    setup_user_certificates();

    EXPECT_EQ(0, ret);
}

TEST(beluga_adaptor_setting, beluga_adaptor_sa_split_files){    
    sa_error_e ret = SA_ERROR_NONE;
    char *orig_config_file = "/opt/beluga/setup-adaptor/config/config.json";
    char sa_config_file_path[2][256] = {
        "/opt/beluga/setup-adaptor/config/devconfig_system.json"
        "/opt/beluga/setup-adaptor/config/devconfig_target.json"
    };

    _D("[UNIT_TEST] sa_split_files ~~~~~");

    sa_split_files(orig_config_file, sa_config_file_path[0], sa_config_file_path[1]);

    EXPECT_EQ(SA_ERROR_NONE, ret);
}

TEST(beluga_adaptor_setting, beluga_adaptor_sa_inputfile_get_config_info){    
    int flagInitialized = 0;
    sa_error_e ret = SA_ERROR_NONE;
    sa_config_s config = { 0, };    
    char *file_path = "/opt/beluga/setup-adaptor/config/config.json";

    _D("[UNIT_TEST] sa_inputfile_get_config_info ~~~~~");

    ret = sa_inputfile_get_config_info(&config, file_path);
    sa_inputfile_release_resource(&config);

    EXPECT_EQ(SA_ERROR_NONE, ret);
}

TEST(beluga_adaptor_setting, beluga_adaptor_sa_setup_system){
    int flagInitialized = 0;
    sa_error_e ret = SA_ERROR_NONE;
    sa_config_s config = { 0, };
    char *file_path = "/opt/beluga/setup-adaptor/config/config.json";

    _D("[UNIT_TEST] sa_inputfile_get_config_info ~~~~~");

    ret = sa_inputfile_get_config_info(&config, file_path);

    if (ret == SA_ERROR_NONE) {
        if (config.systemData != NULL)
        {
            ret = sa_setup_system(config.systemData, flagInitialized);
            if (ret != SA_ERROR_NONE)
                _E("sa_setup_system return error(%d)", ret);
            _D("sa_setup_system() completed !!! ret(%d)", ret);
        }        
    }
    sa_inputfile_release_resource(&config);
    _D("setup_cb completed <<<<<<<<<<<<<<<<<<<<<<<<");

    EXPECT_EQ(SA_ERROR_NONE, ret);
}

TEST(beluga_adaptor_setting, beluga_adaptor_sa_remove_config_file){
    sa_error_e ret = SA_ERROR_NONE;

    _D("[UNIT_TEST] sa_remove_config_file ~~~~~");

    ret = sa_remove_config_file();

    EXPECT_EQ(SA_ERROR_NONE, ret);
}

TEST(beluga_adaptor_setting, beluga_adaptor_setting_main_thread){

    pthread_t t_setting;
    int ret = 0;
    char cmd_gen_socket[128] = "sudo touch /var/run/beluga_launcher_notify.sock";
    
    ret = CLI_command(cmd_gen_socket, 0, NULL);

    _D("[UNIT_TEST] pthread_create >>> SETTING_MAIN !!!");
    ret = pthread_create(&t_setting, NULL, &setting_main_thread, (void *)NULL);
    if (ret < 0) {
        _E("[UNIT_TEST][SETTING_MAIN] thread create error (ret=%d)", ret);
        ret = -1;
    }
    sleep(5);
    pthread_cancel(t_setting);

    EXPECT_EQ(0, ret);
}

TEST(beluga_adaptor_setting, beluga_adaptor_setting_main_thread_compare_config_file){

    pthread_t t_setting;
    int ret = 0;
    char cmd_gen_socket[128] = "sudo touch /var/run/beluga_launcher_notify.sock";
    char cmd_copy_config_file[256] = "sudo cp /opt/beluga/setup-adaptor/config/devconfig_system.json /opt/beluga/setup-adaptor/config/devconfig_system_applied.json";
    
    ret = CLI_command(cmd_gen_socket, 0, NULL);
    ret = CLI_command(cmd_copy_config_file, 0, NULL);

    _D("[UNIT_TEST] pthread_create >>> SETTING_MAIN !!!");
    ret = pthread_create(&t_setting, NULL, &setting_main_thread, (void *)NULL);
    if (ret < 0) {
        _E("[UNIT_TEST][SETTING_MAIN] thread create error (ret=%d)", ret);
        ret = -1;
    }
    sleep(5);
    pthread_cancel(t_setting);

    EXPECT_EQ(0, ret);
}

TEST(beluga_adaptor_setting, DISABLED_beluga_adaptor_send_message_to_launcher){

    int ret = 0;

    ret = send_message_to_launcher(SA_START_LAUNCHER_SVC);

    EXPECT_EQ(0, ret);
}