DynString_equal_c_str
This commit is contained in:
@@ -39,11 +39,11 @@ const char* DynString_c_str(const DynString* dstr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool DynString_equal(const DynString* s1, const DynString* s2) {
|
bool DynString_equal(const DynString* s1, const DynString* s2) {
|
||||||
if (s1->len != s2->len) {
|
if (s1->data == NULL || s2->data == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s1->data == NULL || s2->data == NULL) {
|
if (s1->len != s2->len) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +56,24 @@ bool DynString_equal(const DynString* s1, const DynString* s2) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DynString_equal_c_str(const DynString* s1, const char* s2) {
|
||||||
|
if (s1->data == NULL || s2 == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s1->len != strlen(s2)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < s1->len; i++) {
|
||||||
|
if (s1->data[i] != s2[i]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void DynString_reserve(DynString* dstr, const size_t new_capacity) {
|
void DynString_reserve(DynString* dstr, const size_t new_capacity) {
|
||||||
if (dstr->capacity >= new_capacity) {
|
if (dstr->capacity >= new_capacity) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ void DynString_free(DynString* dstr);
|
|||||||
bool DynString_is_null(const DynString* dstr);
|
bool DynString_is_null(const DynString* dstr);
|
||||||
const char* DynString_c_str(const DynString* dstr);
|
const char* DynString_c_str(const DynString* dstr);
|
||||||
bool DynString_equal(const DynString* s1, const DynString* s2);
|
bool DynString_equal(const DynString* s1, const DynString* s2);
|
||||||
|
bool DynString_equal_c_str(const DynString* s1, const char* s2);
|
||||||
void DynString_concat_c_str(
|
void DynString_concat_c_str(
|
||||||
DynString* dstr,
|
DynString* dstr,
|
||||||
const char* str,
|
const char* str,
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ PltfWin32State pltf_state = {
|
|||||||
|
|
||||||
#undef PLTF_KEYS_X
|
#undef PLTF_KEYS_X
|
||||||
|
|
||||||
bool pltf_has_wgl_extension(const DynString* name) {
|
bool pltf_has_wgl_extension(const char* name) {
|
||||||
for (size_t i = 0; i < pltf_state.wgl_extensions.len; i++) {
|
for (size_t i = 0; i < pltf_state.wgl_extensions.len; i++) {
|
||||||
if (DynString_equal(name, DynArray_DynString_at(&pltf_state.wgl_extensions, i))) {
|
if (DynString_equal_c_str(DynArray_DynString_at(&pltf_state.wgl_extensions, i), name)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,13 +33,6 @@ bool pltf_has_wgl_extension(const DynString* name) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pltf_has_wgl_extension_c_str(const char* name) {
|
|
||||||
DynString name_dstr = DynString_alloc(name, strlen(name));
|
|
||||||
const bool res = pltf_has_wgl_extension(&name_dstr);
|
|
||||||
DynString_free(&name_dstr);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int vk_to_pltf_key(WPARAM key) {
|
unsigned int vk_to_pltf_key(WPARAM key) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case VK_ESCAPE:
|
case VK_ESCAPE:
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ typedef struct {
|
|||||||
extern PltfWin32State pltf_state;
|
extern PltfWin32State pltf_state;
|
||||||
extern HMODULE opengl_module;
|
extern HMODULE opengl_module;
|
||||||
|
|
||||||
bool pltf_has_wgl_extension(const DynString* name);
|
bool pltf_has_wgl_extension(const char* name);
|
||||||
bool pltf_has_wgl_extension_c_str(const char* name);
|
// bool pltf_has_wgl_extension_c_str(const char* name);
|
||||||
unsigned int vk_to_pltf_key(WPARAM key);
|
unsigned int vk_to_pltf_key(WPARAM key);
|
||||||
|
|
||||||
#endif // PLTF_WIN32_INTERNAL_H_
|
#endif // PLTF_WIN32_INTERNAL_H_
|
||||||
|
|||||||
@@ -156,10 +156,10 @@ void pltf_gl_ctx_create() {
|
|||||||
|
|
||||||
free(wgl_extensions_str);
|
free(wgl_extensions_str);
|
||||||
|
|
||||||
if (!pltf_has_wgl_extension_c_str("WGL_ARB_pixel_format")) {
|
if (!pltf_has_wgl_extension("WGL_ARB_pixel_format")) {
|
||||||
LOG_FATAL("WGL_ARB_create_context extension required.");
|
LOG_FATAL("WGL_ARB_create_context extension required.");
|
||||||
}
|
}
|
||||||
if (!pltf_has_wgl_extension_c_str("WGL_ARB_create_context")) {
|
if (!pltf_has_wgl_extension("WGL_ARB_create_context")) {
|
||||||
LOG_FATAL("WGL_ARB_create_context extension is required");
|
LOG_FATAL("WGL_ARB_create_context extension is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
28
tests/main.c
28
tests/main.c
@@ -34,10 +34,33 @@ void test_DynString_equal(void** state) {
|
|||||||
DynString_free(&s2);
|
DynString_free(&s2);
|
||||||
|
|
||||||
s1 = DynString_alloc("Hello", strlen("Hello"));
|
s1 = DynString_alloc("Hello", strlen("Hello"));
|
||||||
s2 = DynString_alloc("Hello", strlen("Hello"));
|
s2 = DynString_alloc("Hell0", strlen("Hell0"));
|
||||||
assert_true(DynString_equal(&s1, &s2));
|
assert_false(DynString_equal(&s1, &s2));
|
||||||
DynString_free(&s1);
|
DynString_free(&s1);
|
||||||
DynString_free(&s2);
|
DynString_free(&s2);
|
||||||
|
|
||||||
|
s1 = DynString_alloc("Hello World", strlen("Hello World"));
|
||||||
|
s2 = DynString_alloc("Hello", strlen("Hello"));
|
||||||
|
assert_false(DynString_equal(&s1, &s2));
|
||||||
|
DynString_free(&s1);
|
||||||
|
DynString_free(&s2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_DynString_equal_c_str(void** state) {
|
||||||
|
DynString s1 = DynString_alloc("Hello", strlen("Hello"));
|
||||||
|
char* s2 = "Hello";
|
||||||
|
assert_true(DynString_equal_c_str(&s1, s2));
|
||||||
|
DynString_free(&s1);
|
||||||
|
|
||||||
|
s1 = DynString_alloc("Hello", strlen("Hello"));
|
||||||
|
s2 = "Hell0";
|
||||||
|
assert_false(DynString_equal_c_str(&s1, s2));
|
||||||
|
DynString_free(&s1);
|
||||||
|
|
||||||
|
s1 = DynString_alloc("Hello World", strlen("Hello World"));
|
||||||
|
s2 = "Hello";
|
||||||
|
assert_false(DynString_equal_c_str(&s1, s2));
|
||||||
|
DynString_free(&s1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_DynString_concat_c_str(void** state) {
|
void test_DynString_concat_c_str(void** state) {
|
||||||
@@ -71,6 +94,7 @@ int main() {
|
|||||||
cmocka_unit_test(test_DynString_alloc),
|
cmocka_unit_test(test_DynString_alloc),
|
||||||
cmocka_unit_test(test_DynString_free),
|
cmocka_unit_test(test_DynString_free),
|
||||||
cmocka_unit_test(test_DynString_equal),
|
cmocka_unit_test(test_DynString_equal),
|
||||||
|
cmocka_unit_test(test_DynString_equal_c_str),
|
||||||
cmocka_unit_test(test_DynString_concat_c_str),
|
cmocka_unit_test(test_DynString_concat_c_str),
|
||||||
cmocka_unit_test(test_DynString_c_str),
|
cmocka_unit_test(test_DynString_c_str),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user