Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
test-safeclib.c
Go to the documentation of this file.
1/*
2 TEST-SAFECLIB - some checked C operations
3
4 Copyright (C)
5 2008, Christian Thaeter <ct@pipapo.org>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
20#include "lib/safeclib.h"
21#include "lib/tmpbuf.h" /* not factored out yet */
22#include "lib/test/test.h"
23
24#include <sys/time.h>
25#include <sys/resource.h>
26
28
29TEST (allocation0)
30{
32 NOTREACHED();
33}
34
35TEST (allocation1024)
36{
37 void* data[1024];
38 for (int i = 0; i < 1024; ++i)
39 {
40 data[i] = lumiera_malloc (1024);
41 CHECK (data[i]);
42 }
43 for (int i = 0; i < 1024; ++i)
44 {
45 free (data[i]);
46 }
47}
48
49TEST (allocationtoobig)
50{
51 struct rlimit rl;
52 rl.rlim_cur = 100*1024*1024;
53 rl.rlim_max = 100*1024*1024;
54 setrlimit (RLIMIT_AS, &rl);
55 lumiera_malloc (200*1024*1024);
56 NOTREACHED();
57}
58
59TEST (streq)
60{
61 CHECK (lumiera_streq ("foo", "foo"));
62 CHECK (lumiera_streq (NULL, NULL));
63 CHECK (!lumiera_streq (NULL, "foo"));
64 CHECK (!lumiera_streq ("foo", NULL));
65 CHECK (!lumiera_streq ("foo", "bar"));
66}
67
68TEST (tmpbuf)
69{
70 for (int i = 0; i < 256; ++i)
71 {
72 char* buf = lumiera_tmpbuf_provide (1024);
73
74 for (int j = 0; j < 1024; ++j)
75 {
76 buf[j] = i;
77 }
78 }
79}
80
81
82TEST (tr0)
83{
84 char* r = lumiera_tmpbuf_tr (argv[2], "abcdeABCDE0123456789", "ABCDEABCDE0123456789", NULL);
85 printf("%s\n", r?r:"failed");
86}
87
88
89TEST (tr)
90{
91 char* r = lumiera_tmpbuf_tr (argv[2], "abcdeABCDE0123456789", "ABCDEABCDE0123456789", "");
92 printf("%s\n", r?r:"failed");
93}
94
95
96TEST (tr_)
97{
98 printf("%s\n", lumiera_tmpbuf_tr (argv[2], "abcdeABCDE0123456789", "ABCDEABCDE0123456789", "_"));
99}
100
101
return NULL
Definition llist.h:586
int lumiera_streq(const char *a, const char *b)
check 2 strings for identity.
Definition safeclib.c:191
void * lumiera_malloc(size_t size)
Allocate memory.
Definition safeclib.c:113
Portable and safe wrappers around some C-Lib functions.
Helpers and support macros for defining test executables in C.
#define TEST(name)
Definition test.h:45
#define TESTS_END
Definition test.h:55
#define TESTS_BEGIN
Definition test.h:34
char * lumiera_tmpbuf_tr(const char *in, const char *from, const char *to, const char *def)
Translates characters in a string, similar to the shell 'tr' utility.
Definition tmpbuf.c:147
void * lumiera_tmpbuf_provide(size_t size)
Query a thread local tmpbuf.
Definition tmpbuf.c:80
Round robin temporary buffers.