c-unittests: replace #define with C++ const, use SUBCASEs more
#include "qdr_doctest.h"
-#define TESTING 1 //not used?
extern "C" {
-#include <stdio.h>
-#include <stdint.h>
+#include <../src/router_core/router_core_private.h>
+#include <../src/terminus_private.h>
#include <inttypes.h>
#include <qpid/dispatch/router_core.h>
-#include <../src/router_core/router_core_private.h>
-int safe_snprintf(char *str, size_t size, const char *format, ...);
+#include <stdint.h>
+#include <stdio.h>
}
-#define OUTPUT_SIZE 128
-#define TEST_MESSAGE "something"
-#define LEN strlen(TEST_MESSAGE)
+TEST_CASE("test_safe_snprintf") {
+ const int OUTPUT_SIZE = 128;
+ const char *TEST_MESSAGE = "something";
+ const int LEN = strlen(TEST_MESSAGE);
-TEST_CASE("test_safe_snprintf_valid_input") {
- //size_t size = OUTPUT_SIZE;
size_t len;
char output[OUTPUT_SIZE];
+ SUBCASE("valid_inputs") {
+ SUBCASE("") {
len = safe_snprintf(output, LEN + 10, TEST_MESSAGE);
CHECK(LEN == len);
CHECK(output == TEST_MESSAGE);
+ }
+ SUBCASE("") {
len = safe_snprintf(output, LEN + 1, TEST_MESSAGE);
CHECK(LEN == len);
CHECK(output == TEST_MESSAGE);
+ }
+ SUBCASE("") {
len = safe_snprintf(output, LEN, TEST_MESSAGE);
CHECK(LEN - 1 == len);
CHECK(output == "somethin");
+ }
+ SUBCASE("") {
len = safe_snprintf(output, 0, TEST_MESSAGE);
CHECK(0 == len);
+ }
+ SUBCASE("") {
output[0] = 'a';
len = safe_snprintf(output, 1, TEST_MESSAGE);
CHECK(0 == len);
CHECK('\0' == output[0]);
+ }
+ SUBCASE("") {
len = safe_snprintf(output, (int)-1, TEST_MESSAGE);
- CHECK(0 == len); //or worst negative?
-
+ CHECK(0 == len);
+ }
+ }
}
-TEST_CASE("test_qdr_terminus_format_coordinator") {
- qdr_terminus_t t;
-#define SIZE 128
-#define EXPECTED "{<coordinator>}"
-#define EXPECTED_LEN strlen(EXPECTED)
+TEST_CASE("test_qdr_terminus_format") {
+ SUBCASE("coordinator") {
+ const int SIZE = 128;
+ const char *EXPECTED = "{<coordinator>}";
+ const int EXPECTED_LEN = strlen(EXPECTED);
+
size_t size = SIZE;
char output[SIZE];
+ qdr_terminus_t t;
t.coordinator = true;
qdr_terminus_format(&t, output, &size);
CHECK(output == EXPECTED);
- //EXPECT_STREQ(output, "wrong_but_continues");
CHECK(size == SIZE - EXPECTED_LEN);
-
-#undef SIZE
-#undef EXPECTED
-#undef EXPECTED_LEN
}
-TEST_CASE("test_qdr_terminus_format_empty") {
+ SUBCASE("empty") {
char output[3];
size_t size = 3;
output[2] = 'A';
+ SUBCASE("") {
qdr_terminus_format(NULL, output, &size);
- SUBCASE("Sample subcase 1") {
CHECK(output == "{}");
- }
- SUBCASE("Sample subcase 2") {
CHECK(size == 1);
}
}
+}
