| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 |
|
|---|
| 4 | libreplace tests
|
|---|
| 5 |
|
|---|
| 6 | Copyright (C) Jelmer Vernooij 2006
|
|---|
| 7 |
|
|---|
| 8 | ** NOTE! The following LGPL license applies to the talloc
|
|---|
| 9 | ** library. This does NOT imply that all of Samba is released
|
|---|
| 10 | ** under the LGPL
|
|---|
| 11 |
|
|---|
| 12 | This library is free software; you can redistribute it and/or
|
|---|
| 13 | modify it under the terms of the GNU Lesser General Public
|
|---|
| 14 | License as published by the Free Software Foundation; either
|
|---|
| 15 | version 2 of the License, or (at your option) any later version.
|
|---|
| 16 |
|
|---|
| 17 | This library is distributed in the hope that it will be useful,
|
|---|
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 20 | Lesser General Public License for more details.
|
|---|
| 21 |
|
|---|
| 22 | You should have received a copy of the GNU Lesser General Public
|
|---|
| 23 | License along with this library; if not, write to the Free Software
|
|---|
| 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 25 | */
|
|---|
| 26 |
|
|---|
| 27 | #include "replace.h"
|
|---|
| 28 |
|
|---|
| 29 | /*
|
|---|
| 30 | we include all the system/ include files here so that libreplace tests
|
|---|
| 31 | them in the build farm
|
|---|
| 32 | */
|
|---|
| 33 | #include "system/capability.h"
|
|---|
| 34 | #include "system/dir.h"
|
|---|
| 35 | #include "system/filesys.h"
|
|---|
| 36 | #include "system/glob.h"
|
|---|
| 37 | #include "system/iconv.h"
|
|---|
| 38 | #include "system/locale.h"
|
|---|
| 39 | #include "system/network.h"
|
|---|
| 40 | #include "system/passwd.h"
|
|---|
| 41 | #include "system/printing.h"
|
|---|
| 42 | #include "system/readline.h"
|
|---|
| 43 | #include "system/select.h"
|
|---|
| 44 | #include "system/shmem.h"
|
|---|
| 45 | #include "system/syslog.h"
|
|---|
| 46 | #include "system/terminal.h"
|
|---|
| 47 | #include "system/time.h"
|
|---|
| 48 | #include "system/wait.h"
|
|---|
| 49 | #include "system/aio.h"
|
|---|
| 50 |
|
|---|
| 51 | #define TESTFILE "testfile.dat"
|
|---|
| 52 |
|
|---|
| 53 | /*
|
|---|
| 54 | test ftruncate() function
|
|---|
| 55 | */
|
|---|
| 56 | static int test_ftruncate(void)
|
|---|
| 57 | {
|
|---|
| 58 | struct stat st;
|
|---|
| 59 | int fd;
|
|---|
| 60 | const int size = 1234;
|
|---|
| 61 | printf("test: ftruncate\n");
|
|---|
| 62 | unlink(TESTFILE);
|
|---|
| 63 | fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
|
|---|
| 64 | if (fd == -1) {
|
|---|
| 65 | printf("failure: ftruncate [\n"
|
|---|
| 66 | "creating '%s' failed - %s\n]\n", TESTFILE, strerror(errno));
|
|---|
| 67 | return false;
|
|---|
| 68 | }
|
|---|
| 69 | if (ftruncate(fd, size) != 0) {
|
|---|
| 70 | printf("failure: ftruncate [\n%s\n]\n", strerror(errno));
|
|---|
| 71 | return false;
|
|---|
| 72 | }
|
|---|
| 73 | if (fstat(fd, &st) != 0) {
|
|---|
| 74 | printf("failure: ftruncate [\nfstat failed - %s\n]\n", strerror(errno));
|
|---|
| 75 | return false;
|
|---|
| 76 | }
|
|---|
| 77 | if (st.st_size != size) {
|
|---|
| 78 | printf("failure: ftruncate [\ngave wrong size %d - expected %d\n]\n",
|
|---|
| 79 | (int)st.st_size, size);
|
|---|
| 80 | return false;
|
|---|
| 81 | }
|
|---|
| 82 | unlink(TESTFILE);
|
|---|
| 83 | printf("success: ftruncate\n");
|
|---|
| 84 | return true;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | /*
|
|---|
| 88 | test strlcpy() function.
|
|---|
| 89 | see http://www.gratisoft.us/todd/papers/strlcpy.html
|
|---|
| 90 | */
|
|---|
| 91 | static int test_strlcpy(void)
|
|---|
| 92 | {
|
|---|
| 93 | char buf[4];
|
|---|
| 94 | const struct {
|
|---|
| 95 | const char *src;
|
|---|
| 96 | size_t result;
|
|---|
| 97 | } tests[] = {
|
|---|
| 98 | { "abc", 3 },
|
|---|
| 99 | { "abcdef", 6 },
|
|---|
| 100 | { "abcd", 4 },
|
|---|
| 101 | { "", 0 },
|
|---|
| 102 | { NULL, 0 }
|
|---|
| 103 | };
|
|---|
| 104 | int i;
|
|---|
| 105 | printf("test: strlcpy\n");
|
|---|
| 106 | for (i=0;tests[i].src;i++) {
|
|---|
| 107 | if (strlcpy(buf, tests[i].src, sizeof(buf)) != tests[i].result) {
|
|---|
| 108 | printf("failure: strlcpy [\ntest %d failed\n]\n", i);
|
|---|
| 109 | return false;
|
|---|
| 110 | }
|
|---|
| 111 | }
|
|---|
| 112 | printf("success: strlcpy\n");
|
|---|
| 113 | return true;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | static int test_strlcat(void)
|
|---|
| 117 | {
|
|---|
| 118 | /* FIXME */
|
|---|
| 119 | return true;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | static int test_mktime(void)
|
|---|
| 123 | {
|
|---|
| 124 | /* FIXME */
|
|---|
| 125 | return true;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | static int test_innetgr(void)
|
|---|
| 129 | {
|
|---|
| 130 | /* FIXME */
|
|---|
| 131 | return true;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | static int test_initgroups(void)
|
|---|
| 135 | {
|
|---|
| 136 | /* FIXME */
|
|---|
| 137 | return true;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | static int test_memmove(void)
|
|---|
| 141 | {
|
|---|
| 142 | /* FIXME */
|
|---|
| 143 | return true;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | static int test_strdup(void)
|
|---|
| 147 | {
|
|---|
| 148 | /* FIXME */
|
|---|
| 149 | return true;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | static int test_setlinebuf(void)
|
|---|
| 153 | {
|
|---|
| 154 | printf("test: setlinebuf\n");
|
|---|
| 155 | setlinebuf(stdout);
|
|---|
| 156 | printf("success: setlinebuf\n");
|
|---|
| 157 | return true;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | static int test_vsyslog(void)
|
|---|
| 161 | {
|
|---|
| 162 | /* FIXME */
|
|---|
| 163 | return true;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | static int test_timegm(void)
|
|---|
| 167 | {
|
|---|
|
|---|