source: mainline/uspace/lib/c/test/mem.c@ cd1e3fc0

Last change on this file since cd1e3fc0 was d7f7a4a, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Replace some license headers with SPDX identifier

Headers are replaced using tools/transorm-copyright.sh only
when it can be matched verbatim with the license header used
throughout most of the codebase.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/*
2 * SPDX-FileCopyrightText: 2018 Jiri Svoboda
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <mem.h>
8#include <pcut/pcut.h>
9
10PCUT_INIT;
11
12PCUT_TEST_SUITE(mem);
13
14/** memcpy function */
15PCUT_TEST(memcpy)
16{
17 char buf[5];
18 void *p;
19
20 p = memcpy(buf, "abc\0d", 5);
21 PCUT_ASSERT_TRUE(p == buf);
22
23 PCUT_ASSERT_INT_EQUALS('a', buf[0]);
24 PCUT_ASSERT_INT_EQUALS('b', buf[1]);
25 PCUT_ASSERT_INT_EQUALS('c', buf[2]);
26 PCUT_ASSERT_INT_EQUALS('\0', buf[3]);
27 PCUT_ASSERT_INT_EQUALS('d', buf[4]);
28}
29
30/** memmove function */
31PCUT_TEST(memmove)
32{
33 char buf[] = "abc\0d";
34 void *p;
35
36 p = memmove(buf, buf + 1, 4);
37 PCUT_ASSERT_TRUE(p == buf);
38
39 PCUT_ASSERT_INT_EQUALS('b', buf[0]);
40 PCUT_ASSERT_INT_EQUALS('c', buf[1]);
41 PCUT_ASSERT_INT_EQUALS('\0', buf[2]);
42 PCUT_ASSERT_INT_EQUALS('d', buf[3]);
43 PCUT_ASSERT_INT_EQUALS('d', buf[4]);
44}
45
46/** memcmp function */
47PCUT_TEST(memcmp)
48{
49 const char *s1 = "ab" "\0" "1d";
50 const char *s2 = "ab" "\0" "2d";
51 int c;
52
53 c = memcmp(s1, s2, 3);
54 PCUT_ASSERT_INT_EQUALS(0, c);
55
56 c = memcmp(s1, s2, 4);
57 PCUT_ASSERT_TRUE(c < 0);
58
59 c = memcmp(s2, s1, 4);
60 PCUT_ASSERT_TRUE(c > 0);
61}
62
63/** memchr function */
64PCUT_TEST(memchr)
65{
66 const char *s = "abc\0d";
67 void *p;
68
69 p = memchr(s, 'd', 5);
70 PCUT_ASSERT_TRUE(p == s + 4);
71
72 p = memchr(s, '\0', 5);
73 PCUT_ASSERT_TRUE(p == s + 3);
74
75 p = memchr(s, 'd', 4);
76 PCUT_ASSERT_TRUE(p == NULL);
77}
78
79/** memset function */
80PCUT_TEST(memset)
81{
82 char buf[5];
83 void *p;
84
85 buf[0] = buf[1] = buf[2] = buf[3] = buf[4] = 'a';
86 p = memset(buf, 'x', 5);
87 PCUT_ASSERT_TRUE(p == buf);
88
89 PCUT_ASSERT_INT_EQUALS('x', buf[0]);
90 PCUT_ASSERT_INT_EQUALS('x', buf[1]);
91 PCUT_ASSERT_INT_EQUALS('x', buf[2]);
92 PCUT_ASSERT_INT_EQUALS('x', buf[3]);
93 PCUT_ASSERT_INT_EQUALS('x', buf[4]);
94}
95
96PCUT_EXPORT(mem);
Note: See TracBrowser for help on using the repository browser.