From: yu.dongliang <18588496441@163.com> Date: Mon, 27 Nov 2023 04:27:41 +0000 (+0800) Subject: delete & revise some test code X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=cbadb4a49b68eb13df6e1c21157a2362c871c76c;p=scf.git delete & revise some test code --- diff --git a/test/list_test.c b/test/list_test.c index a50f853..f5d179c 100644 --- a/test/list_test.c +++ b/test/list_test.c @@ -1,19 +1,5 @@ -struct list -{ - list* prev; - list* next; -}; - -inline void list_init(list* h); -inline list* list_head(list* h); -inline list* list_tail(list* h); -inline list* list_sentinel(list* h); -inline list* list_next(list* n); -inline list* list_prev(list* n); -inline void list_del(list* n); -inline int list_empty(list* h); -inline void list_add_tail(list* h, list* n); -inline void list_add_front(list* h, list* n); +include "../lib/scf_list.c"; +include "../lib/scf_capi.c"; struct Data { @@ -21,10 +7,6 @@ struct Data int a; }; -void* scf__malloc(uintptr_t size); -int scf__free(void* p); -int scf_printf(const char* fmt, ...); - int main() { Data* d; @@ -33,8 +15,8 @@ int main() list_init(&h); - for (i = 0; i < 3; i++) { - d = scf__malloc(sizeof(Data)); + for (i = 0; i < 10; i++) { + d = malloc(sizeof(Data)); d->a = i; list_add_tail(&h, &d->list); @@ -47,12 +29,11 @@ int main() d = container(l, Data, list); l = list_next(l); - scf_printf("%d\n", d->a); + printf("%d\n", d->a); list_del(&d->list); - scf__free(d); + free(d); } return 0; } - diff --git a/test/object.c b/test/object.c deleted file mode 100644 index 7192559..0000000 --- a/test/object.c +++ /dev/null @@ -1,39 +0,0 @@ - -struct scf_object_t -{ - intptr_t refs; - uintptr_t size; -}; - -int scf_printf(const char* fmt, ...); - -void scf__release_pt(void* objdata); - -void* scf__auto_malloc(uintptr_t size); - -void scf__auto_freep(void** pp, scf__release_pt* release); - -void scf__auto_freep_array(void** pp, int nb_pointers, scf__release_pt* release); - -void scf__auto_free_array(void** pp, int size, int nb_pointers, scf__release_pt* release); - -void scf__auto_ref(void* data); - - -int main() -{ - int** pp = scf__auto_malloc(sizeof(int*) * 4); - - scf_printf("pp: %p\n\n", pp); - - int i; - for (i = 0; i < 4; i++) { - int* p = scf__auto_malloc(sizeof(int)); - - pp[i] = p; - scf_printf("\n"); - } - - return 0; -} - diff --git a/test/printf.c b/test/printf.c deleted file mode 100644 index 27525bb..0000000 --- a/test/printf.c +++ /dev/null @@ -1,17 +0,0 @@ - -int scf_printf(const char* fmt, ...); - -int main() -{ - char buf[1024]; - - float f = 2.71828; - double d = -3.1415926; - int64_t i64 = -255; - - int ret = scf_printf("i: %d, ld: %ld, x: %x, x: %#lx, p: %p, s: %s, f: %f, d: %lf\n", - 100, i64, 254, 253, buf, "hello", f, -3.14); - - return ret; -} - diff --git a/test/qsort.c b/test/qsort.c deleted file mode 100644 index e3e5ff9..0000000 --- a/test/qsort.c +++ /dev/null @@ -1,42 +0,0 @@ -int scf_printf(const char* fmt, ...); - -int sort(int* a, int m, int n) -{ - if (m >= n) - return 0; - - int i = m; - int j = n; - int t; - - t = a[i]; - while (i < j) { - - while (i < j && t <= a[j]) - j--; - a[i] = a[j]; - a[j] = t; - - while (i < j && a[i] <= t) - i++; - a[j] = a[i]; - a[i] = t; - } - - sort(a, m, i - 1); - sort(a, i + 1, n); - return 0; -} - -int main() -{ - int a[10] = {11, 13, 15, 17, 19, 18, 16, 14, 12, 10}; - - sort(a, 0, 9); - - int i; - for (i = 0; i < 10; i++) - scf_printf("%d\n", a[i]); - - return 0; -} diff --git a/test/rbtree.c b/test/rbtree.c index 4692eab..26d08b1 100644 --- a/test/rbtree.c +++ b/test/rbtree.c @@ -92,4 +92,3 @@ int main() return 0; } - diff --git a/test/scf_atomic_test.c b/test/scf_atomic_test.c deleted file mode 100644 index 0542287..0000000 --- a/test/scf_atomic_test.c +++ /dev/null @@ -1,46 +0,0 @@ - -#include -#include -#include - -int64_t v = 0; - -void scf__atomic_inc(int64_t* p); -void scf__atomic_dec(int64_t* p); -int scf__atomic_dec_and_test(int64_t* p); - -void* thread(void* p) -{ - int64_t *pi = p; - int i; - for (i = 0; i < 1000 * 1000; i++) - scf__atomic_inc(p); - return NULL; -} - -int main() -{ - scf__atomic_inc(&v); - printf("v: %ld\n", v); - - scf__atomic_inc(&v); - printf("v: %ld\n", v); - - scf__atomic_dec(&v); - printf("v: %ld\n", v); - - int ret = scf__atomic_dec_and_test(&v); - printf("v: %ld, ret: %d\n", v, ret); - - pthread_t tid; - pthread_create(&tid, NULL, thread, &v); - - int i; - for (i = 0; i < 1000 * 1000; i++) - scf__atomic_inc(&v); - - pthread_join(tid, NULL); - - printf("v: %ld\n", v); - return 0; -} diff --git a/test/scf_printf.c b/test/scf_printf.c index f5d0f9e..5ffc7ef 100644 --- a/test/scf_printf.c +++ b/test/scf_printf.c @@ -9,8 +9,6 @@ struct va_list intptr_t others; }; -int scf__write(int fd, uint8_t* buf, uint64_t size); - int scf_ulong2a(char* buf, int* pn, int size, uint64_t num) { int n = *pn; @@ -229,3 +227,16 @@ int scf_printf(const char* fmt, ...) return ret; } +int main() +{ + char buf[1024]; + + float f = 2.71828; + double d = -3.1415926; + int64_t i64 = -255; + + int ret = scf_printf("i: %d, ld: %ld, x: %x, x: %#lx, p: %p, s: %s, f: %f, d: %lf\n", + 100, i64, 254, 253, buf, "hello", f, -3.14); + + return ret; +} diff --git a/test/str.c b/test/str.c deleted file mode 100644 index e892e56..0000000 --- a/test/str.c +++ /dev/null @@ -1,31 +0,0 @@ - -int scf_printf(const char* fmt, ...); - -uintptr_t scf__strlen (const char *s); -int scf__strcmp (const char *s1, const char *s2); -int scf__strncmp(const char *s1, const char *s2, uintptr_t n); -char* scf__strncpy(char *dst, const char *src, uintptr_t n); - -int main() -{ - char buf[100]; - char* s0 = "hello1"; - char* s1 = "hello2"; - - scf_printf("%s, len: %d\n", s0, scf__strlen(s0)); - - scf_printf("%s, %s, cmp: %d\n", s0, s1, scf__strcmp(s0, s1)); - scf_printf("%s, %s, cmp: %d\n", s1, s0, scf__strcmp(s1, s0)); - scf_printf("%s, %s, cmp: %d\n", s0, s0, scf__strcmp(s0, s0)); - - scf_printf("%s, %s, cmp: %d, n: %d\n", s0, s1, scf__strncmp(s0, s1, 5), 5); - - scf__strncpy(buf, s0, 5); - scf_printf("buf: %s\n", buf); - - scf__strncpy(buf, s0, 6); - scf_printf("buf: %s\n", buf); - - return 0; -} - diff --git a/test/string.c b/test/string.c index d2841fa..81b522b 100644 --- a/test/string.c +++ b/test/string.c @@ -1,22 +1,4 @@ - -void scf__release_pt (void* objdata); - -void* scf__auto_malloc(uintptr_t size); -void scf__auto_ref(void* data); - -void scf__auto_freep (void** pp, scf__release_pt* release); -void scf__auto_freep_array(void** pp, int nb_pointers, scf__release_pt* release); -void scf__auto_free_array (void** pp, int size, int nb_pointers, scf__release_pt* release); - -uintptr_t strlen (const char *s); -int strcmp (const char *s1, const char *s2); -int strncmp(const char *s1, const char *s2, uintptr_t n); -char* strncpy(char *dst, const char *src, uintptr_t n); -int memcpy (void* dst, const void* src, uintptr_t n); -int memcmp (void* dst, const void* src, uintptr_t n); - -int scf_printf(const char* fmt, ...); - +include "../lib/scf_capi.c"; struct string { @@ -148,7 +130,7 @@ int main() s2 = s0 + s1; s3 = "hello"; - scf_printf("### s0 == s3: %d, %s\n", s0 == s3, s0->data); + printf("### s0 == s3: %d, s0->data: %s, s2: %s\n", s0 == s3, s0->data, s2->data); return 0; }