-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9382ed0
commit e837734
Showing
22 changed files
with
4,282 additions
and
490 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,75 @@ | ||
#include <stdlib.h> | ||
#include <check.h> | ||
#include <unity.h> | ||
#include "../src/config.h" | ||
|
||
struct server_config *config = NULL; | ||
|
||
START_TEST (test_missing_file) { | ||
int code = create_server_config(&config, "non-existing-configration-file.config"); | ||
ck_assert_int_eq(code, -1); | ||
void test_missing_file() { | ||
int code = create_server_config(&config, "non-existing-configration-file.config"); | ||
TEST_ASSERT_EQUAL_INT(code, -1); | ||
} | ||
END_TEST | ||
|
||
START_TEST (test_invalid_format) { | ||
int code = create_server_config(&config, "invalid.format.config"); | ||
ck_assert_int_eq(code, -1); | ||
void test_invalid_format() { | ||
int code = create_server_config(&config, "invalid.format.config"); | ||
TEST_ASSERT_EQUAL_INT(code, -1); | ||
} | ||
END_TEST | ||
|
||
START_TEST (test_missing_required) { | ||
int code = create_server_config(&config, "invalid.config"); | ||
ck_assert_int_eq(code, -1); | ||
void test_missing_required() { | ||
int code = create_server_config(&config, "invalid.config"); | ||
TEST_ASSERT_EQUAL_INT(code, -1); | ||
} | ||
END_TEST | ||
|
||
START_TEST (test_invalid_timeout) { | ||
int code = create_server_config(&config, "invalid2.config"); | ||
ck_assert_int_eq(code, -1); | ||
void test_invalid_timeout() { | ||
int code = create_server_config(&config, "invalid2.config"); | ||
TEST_ASSERT_EQUAL_INT(code, -1); | ||
} | ||
END_TEST | ||
|
||
START_TEST (test_invalid_queue_size_config) { | ||
int code = create_server_config(&config, "invalid.queue_size.config"); | ||
ck_assert_int_eq(code, -1); | ||
void test_invalid_queue_size_config() { | ||
int code = create_server_config(&config, "invalid.queue_size.config"); | ||
TEST_ASSERT_EQUAL_INT(code, -1); | ||
} | ||
END_TEST | ||
|
||
START_TEST (test_minimal_config) { | ||
int code = create_server_config(&config, "minimal.config"); | ||
ck_assert_int_eq(code, 0); | ||
void test_minimal_config() { | ||
int code = create_server_config(&config, "minimal.config"); | ||
TEST_ASSERT_EQUAL_INT(code, 0); | ||
} | ||
END_TEST | ||
|
||
START_TEST (test_success) { | ||
int code = create_server_config(&config, "configuration.config"); | ||
ck_assert_int_eq(code, 0); | ||
ck_assert_int_eq(2400000, config->band_sampling_rate); | ||
ck_assert_int_eq(1, config->gain_mode); | ||
ck_assert_int_eq(42, config->gain); | ||
ck_assert_int_eq(0, config->bias_t); | ||
ck_assert_int_eq(config->ppm, 10); | ||
ck_assert_int_eq(config->device_index, 1); | ||
ck_assert_str_eq(config->device_serial, "00000400"); | ||
ck_assert_str_eq(config->bind_address, "127.0.0.1"); | ||
ck_assert_int_eq(config->port, 8089); | ||
ck_assert_int_eq(config->buffer_size, 131072); | ||
ck_assert_str_eq(config->base_path, "/tmp/"); | ||
ck_assert_int_eq(config->read_timeout_seconds, 10); | ||
ck_assert_int_eq(config->use_gzip, 0); | ||
ck_assert_int_eq(config->queue_size, 64); | ||
ck_assert_int_eq(config->lpf_cutoff_rate, 5); | ||
void test_success() { | ||
int code = create_server_config(&config, "configuration.config"); | ||
TEST_ASSERT_EQUAL_INT(code, 0); | ||
TEST_ASSERT_EQUAL_INT(2400000, config->band_sampling_rate); | ||
TEST_ASSERT_EQUAL_INT(1, config->gain_mode); | ||
TEST_ASSERT_EQUAL_INT(42, config->gain); | ||
TEST_ASSERT_EQUAL_INT(0, config->bias_t); | ||
TEST_ASSERT_EQUAL_INT(config->ppm, 10); | ||
TEST_ASSERT_EQUAL_INT(config->device_index, 1); | ||
TEST_ASSERT_EQUAL_STRING(config->device_serial, "00000400"); | ||
TEST_ASSERT_EQUAL_STRING(config->bind_address, "127.0.0.1"); | ||
TEST_ASSERT_EQUAL_INT(config->port, 8089); | ||
TEST_ASSERT_EQUAL_INT(config->buffer_size, 131072); | ||
TEST_ASSERT_EQUAL_STRING(config->base_path, "/tmp/"); | ||
TEST_ASSERT_EQUAL_INT(config->read_timeout_seconds, 10); | ||
TEST_ASSERT_EQUAL_INT(config->use_gzip, 0); | ||
TEST_ASSERT_EQUAL_INT(config->queue_size, 64); | ||
TEST_ASSERT_EQUAL_INT(config->lpf_cutoff_rate, 5); | ||
} | ||
END_TEST | ||
|
||
void teardown() { | ||
destroy_server_config(config); | ||
config = NULL; | ||
void tearDown() { | ||
destroy_server_config(config); | ||
config = NULL; | ||
} | ||
|
||
void setup() { | ||
//do nothing | ||
} | ||
|
||
Suite* common_suite(void) { | ||
Suite *s; | ||
TCase *tc_core; | ||
|
||
s = suite_create("config"); | ||
|
||
/* Core test case */ | ||
tc_core = tcase_create("Core"); | ||
|
||
tcase_add_test(tc_core, test_success); | ||
tcase_add_test(tc_core, test_missing_required); | ||
tcase_add_test(tc_core, test_missing_file); | ||
tcase_add_test(tc_core, test_invalid_format); | ||
tcase_add_test(tc_core, test_minimal_config); | ||
tcase_add_test(tc_core, test_invalid_timeout); | ||
tcase_add_test(tc_core, test_invalid_queue_size_config); | ||
|
||
tcase_add_checked_fixture(tc_core, setup, teardown); | ||
suite_add_tcase(s, tc_core); | ||
|
||
return s; | ||
void setUp() { | ||
//do nothing | ||
} | ||
|
||
int main(void) { | ||
int number_failed; | ||
Suite *s; | ||
SRunner *sr; | ||
|
||
s = common_suite(); | ||
sr = srunner_create(s); | ||
|
||
srunner_set_fork_status(sr, CK_NOFORK); | ||
srunner_run_all(sr, CK_NORMAL); | ||
number_failed = srunner_ntests_failed(sr); | ||
srunner_free(sr); | ||
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; | ||
UNITY_BEGIN(); | ||
RUN_TEST(test_success); | ||
RUN_TEST(test_missing_required); | ||
RUN_TEST(test_missing_file); | ||
RUN_TEST(test_invalid_format); | ||
RUN_TEST(test_minimal_config); | ||
RUN_TEST(test_invalid_timeout); | ||
RUN_TEST(test_invalid_queue_size_config); | ||
return UNITY_END(); | ||
} | ||
|
Oops, something went wrong.