File: UtilTest.cpp

package info (click to toggle)
beid 3.5.2.dfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 147,240 kB
  • ctags: 34,507
  • sloc: cpp: 149,944; ansic: 41,577; java: 8,927; cs: 6,528; sh: 2,426; perl: 1,866; xml: 805; python: 463; makefile: 263; lex: 92
file content (145 lines) | stat: -rw-r--r-- 3,914 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* ****************************************************************************

 * eID Middleware Project.
 * Copyright (C) 2008-2009 FedICT.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version
 * 3.0 as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, see
 * http://www.gnu.org/licenses/.

**************************************************************************** */
#include "UnitTest++/src/UnitTest++.h"
#include "../common/Util.h"
#include "../common/Log.h"

using namespace eIDMW;

/*
TEST(utilStringNarrow)
{
//	MWLOG(LEV_WARN, MOD_TEST, "Util String Widen/Narrow, ...\n"); 

    // narrow & widen
    const std::string  sTest  = "Blabla";
    const std::wstring wsTest = L"WideBlabla";
 

//    CHECK_EQUAL(sTest, utilStringNarrow(utilStringWiden(sTest)));

//    std::wstring  wsResult = utilStringWiden(sTest);
//    std::string  sResult = utilStringNarrow(wsTest);
//    CHECK_EQUAL(sTest.c_str(), sResult.c_str());

//    CHECK_EQUAL(wsTest, utilStringWiden(utilStringNarrow(wsTest)));
}
*/

TEST(StartsWith)
{
	CHECK_EQUAL(true, StartsWith("abcdef", "a"));
	CHECK_EQUAL(true, StartsWith("abcdef", "ab"));
	CHECK_EQUAL(true, StartsWith("abcdef", "abcdef"));

	CHECK_EQUAL(false, StartsWith("abcdef", "A"));
	CHECK_EQUAL(false, StartsWith("abcdef", "b"));
	CHECK_EQUAL(false, StartsWith("abcdef", "ac"));
}

TEST(StartsWithCI)
{
	CHECK_EQUAL(true, StartsWithCI("aBcdEf", "a"));
	CHECK_EQUAL(true, StartsWithCI("abcdef", "ab"));
	CHECK_EQUAL(true, StartsWithCI("abcdef", "abcdef"));

	CHECK_EQUAL(false, StartsWithCI("abcdef", "x"));
	CHECK_EQUAL(false, StartsWithCI("abcdef", "ac"));
	CHECK_EQUAL(false, StartsWithCI("abcdef", "df"));
}

#ifndef WIN32

TEST(strcat_s)
{
	char csDest[5];

	csDest[0] = '\0';
	int r = strcat_s(csDest, sizeof(csDest), "abc");
	CHECK_EQUAL(0, r);
	CHECK_EQUAL(0, strcmp(csDest, "abc"));

	r = strcat_s(csDest, sizeof(csDest), "d");
	CHECK_EQUAL(0, r);
	CHECK_EQUAL(0, strcmp(csDest, "abcd"));

	r = strcat_s(csDest, sizeof(csDest), "");
	CHECK_EQUAL(0, r);
	CHECK_EQUAL(0, strcmp(csDest, "abcd"));

	r = strcat_s(csDest, sizeof(csDest), "e");
	CHECK_EQUAL(-1, r);
	CHECK_EQUAL(0, strcmp(csDest, "abcd"));
}

TEST(strcpy_s)
{
	char csDest[5];

	int r = strcpy_s(csDest, sizeof(csDest), "");
	CHECK_EQUAL(0, r);
	CHECK_EQUAL(0, strcmp(csDest, ""));

	r = strcpy_s(csDest, sizeof(csDest), "abcd");
	CHECK_EQUAL(0, r);
	CHECK_EQUAL(0, strcmp(csDest, "abcd"));

	r = strcpy_s(csDest, sizeof(csDest), "abcde");
	CHECK_EQUAL(-1, r);
}

TEST(strncpy_s)
{
	char csDest[5];

	int r = strncpy_s(csDest, sizeof(csDest), "", 1);
	CHECK_EQUAL(0, r);
	CHECK_EQUAL(0, strcmp(csDest, ""));

	r = strncpy_s(csDest, sizeof(csDest), "abcd", 0);
	CHECK_EQUAL(0, r);
	CHECK_EQUAL(0, strcmp(csDest, ""));

	r = strncpy_s(csDest, sizeof(csDest), "abcd", 10);
	CHECK_EQUAL(0, r);
	CHECK_EQUAL(0, strcmp(csDest, "abcd"));

	r = strncpy_s(csDest, sizeof(csDest), "abcdef", 4);
	CHECK_EQUAL(0, r);
	CHECK_EQUAL(0, strcmp(csDest, "abcd"));

	r = strncpy_s(csDest, sizeof(csDest), "abcde", 5);
	CHECK_EQUAL(-1, r);
	CHECK_EQUAL('\0', csDest[0]);
}

TEST(sprintf_s)
{
	char csDest[5];

	int r = sprintf_s(csDest, sizeof(csDest), "%s%s", "ab", "cd");
	CHECK_EQUAL(0, r);
	CHECK_EQUAL(0, strcmp(csDest, "abcd"));

	r = sprintf_s(csDest, sizeof(csDest), "%s%s", "ab", "cde");
	CHECK_EQUAL(-1, r);
}

#endif