added sml_octet_string_cmp
This commit is contained in:
parent
542365df23
commit
aab3c3149d
3 changed files with 19 additions and 0 deletions
|
@ -46,6 +46,7 @@ octet_string *sml_octet_string_parse(sml_buffer *buf);
|
|||
|
||||
void sml_octet_string_write(octet_string *str, sml_buffer *buf);
|
||||
|
||||
int sml_octet_string_cmp(octet_string *s1, octet_string *s2);
|
||||
int sml_octet_string_cmp_with_hex(octet_string *str, char *hex);
|
||||
|
||||
octet_string *sml_octet_string_generate_uuid();
|
||||
|
|
|
@ -105,6 +105,14 @@ octet_string *sml_octet_string_generate_uuid() {
|
|||
#endif
|
||||
}
|
||||
|
||||
int sml_octet_string_cmp(octet_string *s1, octet_string *s2) {
|
||||
if (s1->len != s2->len) {
|
||||
return -1;
|
||||
}
|
||||
return memcmp(s1->str, s2->str, s1->len);
|
||||
}
|
||||
|
||||
|
||||
int sml_octet_string_cmp_with_hex(octet_string *str, char *hex) {
|
||||
octet_string *hstr = sml_octet_string_init_from_hex(hex);
|
||||
if (str->len != hstr->len) {
|
||||
|
|
|
@ -83,6 +83,15 @@ TEST(sml_octet_string, write_optional) {
|
|||
sml_octet_string_expected_buf("01", 1);
|
||||
}
|
||||
|
||||
TEST(sml_octet_string, cmp) {
|
||||
octet_string *s1 = sml_octet_string_init((unsigned char *)"Hallo", 5);
|
||||
octet_string *s2 = sml_octet_string_init((unsigned char *)"Hi", 2);
|
||||
octet_string *s3 = sml_octet_string_init((unsigned char *)"Hallo", 5);
|
||||
|
||||
TEST_ASSERT_TRUE(sml_octet_string_cmp(s1, s2) != 0);
|
||||
TEST_ASSERT_TRUE(sml_octet_string_cmp(s1, s3) == 0);
|
||||
}
|
||||
|
||||
TEST_GROUP_RUNNER(sml_octet_string) {
|
||||
RUN_TEST_CASE(sml_octet_string, init);
|
||||
RUN_TEST_CASE(sml_octet_string, parse);
|
||||
|
@ -90,6 +99,7 @@ TEST_GROUP_RUNNER(sml_octet_string) {
|
|||
RUN_TEST_CASE(sml_octet_string, parse_optional);
|
||||
RUN_TEST_CASE(sml_octet_string, write);
|
||||
RUN_TEST_CASE(sml_octet_string, write_optional);
|
||||
RUN_TEST_CASE(sml_octet_string, cmp);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue