| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include "lcb-message-priv.h" |
| 10 |
|
| 11 |
static void |
| 12 |
test_message_simple (void) |
| 13 |
{ |
| 14 |
LcbMessage *msg; |
| 15 |
|
| 16 |
msg = lcb_message_new ("This is a test", |
| 17 |
4391, 12, 0, 42, LCB_SEVERITY_LEVEL_TEST, |
| 18 |
"Test alert", NULL); |
| 19 |
|
| 20 |
g_assert_cmpstr (lcb_message_get_text (msg), ==, "This is a test"); |
| 21 |
g_assert_cmpuint (lcb_message_get_channel (msg), ==, 4391); |
| 22 |
g_assert_cmpuint (lcb_message_get_msg_code (msg), ==, 12); |
| 23 |
g_assert_cmpuint (lcb_message_get_update (msg), ==, 0); |
| 24 |
g_assert_cmpuint (lcb_message_get_timestamp (msg), ==, 42); |
| 25 |
g_assert_cmpuint (lcb_message_get_severity (msg), ==, LCB_SEVERITY_LEVEL_TEST); |
| 26 |
g_assert_cmpstr (lcb_message_get_severity_subject (msg), ==, "Test alert"); |
| 27 |
g_assert_null (lcb_message_get_operator_code (msg)); |
| 28 |
g_assert_finalize_object (msg); |
| 29 |
|
| 30 |
msg = g_object_new (LCB_TYPE_MESSAGE, |
| 31 |
"text", "This is another test", |
| 32 |
"channel", 4223, |
| 33 |
"message-code", 125, |
| 34 |
"update", 1, |
| 35 |
"timestamp", G_GINT64_CONSTANT (31337), |
| 36 |
"severity", LCB_SEVERITY_LEVEL_PRESIDENTIAL, |
| 37 |
"severity-subject", "Presidential alert", |
| 38 |
"operator-code", "00101", |
| 39 |
NULL); |
| 40 |
|
| 41 |
g_assert_cmpstr (lcb_message_get_text (msg), ==, "This is another test"); |
| 42 |
g_assert_cmpuint (lcb_message_get_channel (msg), ==, 4223); |
| 43 |
g_assert_cmpuint (lcb_message_get_msg_code (msg), ==, 125); |
| 44 |
g_assert_cmpuint (lcb_message_get_update (msg), ==, 1); |
| 45 |
g_assert_cmpuint (lcb_message_get_timestamp (msg), ==, 31337); |
| 46 |
g_assert_cmpuint (lcb_message_get_severity (msg), ==, LCB_SEVERITY_LEVEL_PRESIDENTIAL); |
| 47 |
g_assert_cmpstr (lcb_message_get_severity_subject (msg), ==, "Presidential alert"); |
| 48 |
g_assert_cmpstr (lcb_message_get_operator_code (msg), ==, "00101"); |
| 49 |
g_assert_finalize_object (msg); |
| 50 |
} |
| 51 |
|
| 52 |
static void |
| 53 |
test_message_timestamp (void) |
| 54 |
{ |
| 55 |
g_autoptr (GDateTime) before = NULL; |
| 56 |
g_autoptr (GDateTime) after = NULL; |
| 57 |
LcbMessage *msg; |
| 58 |
gint64 timestamp_before, timestamp_after; |
| 59 |
|
| 60 |
before = g_date_time_new_now_utc (); |
| 61 |
timestamp_before = g_date_time_to_unix (before); |
| 62 |
msg = lcb_message_new ("This is a test", |
| 63 |
4391, 12, 1, 0, LCB_SEVERITY_LEVEL_TEST, |
| 64 |
"It really is a test", NULL); |
| 65 |
|
| 66 |
g_assert_cmpstr (lcb_message_get_text (msg), ==, "This is a test"); |
| 67 |
g_assert_cmpuint (lcb_message_get_channel (msg), ==, 4391); |
| 68 |
g_assert_cmpuint (lcb_message_get_msg_code (msg), ==, 12); |
| 69 |
g_assert_cmpuint (lcb_message_get_update (msg), ==, 1); |
| 70 |
g_assert_cmpuint (lcb_message_get_severity (msg), ==, LCB_SEVERITY_LEVEL_TEST); |
| 71 |
g_assert_cmpstr (lcb_message_get_severity_subject (msg), ==, "It really is a test"); |
| 72 |
|
| 73 |
after = g_date_time_new_now_utc (); |
| 74 |
timestamp_after = g_date_time_to_unix (after); |
| 75 |
|
| 76 |
g_assert_cmpuint (lcb_message_get_timestamp (msg), >=, timestamp_before); |
| 77 |
g_assert_cmpuint (lcb_message_get_timestamp (msg), <=, timestamp_after); |
| 78 |
|
| 79 |
g_assert_finalize_object (msg); |
| 80 |
} |
| 81 |
|
| 82 |
int |
| 83 |
main (int argc, char *argv[]) |
| 84 |
{ |
| 85 |
g_test_init (&argc, &argv, NULL); |
| 86 |
|
| 87 |
g_test_add_func ("/cbd/message/simple", test_message_simple); |
| 88 |
g_test_add_func ("/cbd/message/timestamp", test_message_timestamp); |
| 89 |
|
| 90 |
return g_test_run (); |
| 91 |
} |