2
2
* string-test.c: a collection of libsvn_string tests
4
4
* ====================================================================
5
* Copyright (c) 2000-2004, 2008 CollabNet. All rights reserved.
7
* This software is licensed as described in the file COPYING, which
8
* you should have received as part of this distribution. The terms
9
* are also available at http://subversion.tigris.org/license-1.html.
10
* If newer versions of this license are posted there, you may use a
11
* newer version instead, at your option.
13
* This software consists of voluntary contributions made by many
14
* individuals. For exact contribution history, see the revision
15
* history and logs, available at http://subversion.tigris.org/.
5
* Licensed to the Apache Software Foundation (ASF) under one
6
* or more contributor license agreements. See the NOTICE file
7
* distributed with this work for additional information
8
* regarding copyright ownership. The ASF licenses this file
9
* to you under the Apache License, Version 2.0 (the
10
* "License"); you may not use this file except in compliance
11
* with the License. You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* Unless required by applicable law or agreed to in writing,
16
* software distributed under the License is distributed on an
17
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18
* KIND, either express or implied. See the License for the
19
* specific language governing permissions and limitations
16
21
* ====================================================================
84
81
static svn_error_t *
85
test2(const char **msg,
86
svn_boolean_t msg_only,
87
svn_test_opts_t *opts,
82
test2(apr_pool_t *pool)
90
*msg = "make svn_stringbuf_t from substring of cstring";
95
84
b = svn_stringbuf_ncreate(phrase_2, 16, pool);
97
86
/* Test that length, data, and null-termination are correct. */
159
132
static svn_error_t *
160
test5(const char **msg,
161
svn_boolean_t msg_only,
162
svn_test_opts_t *opts,
133
test5(apr_pool_t *pool)
165
*msg = "append bytes, then compare two strings";
170
135
a = svn_stringbuf_create(phrase_1, pool);
171
136
svn_stringbuf_appendbytes(a, "new bytes to append", 9);
182
147
static svn_error_t *
183
test6(const char **msg,
184
svn_boolean_t msg_only,
185
svn_test_opts_t *opts,
148
test6(apr_pool_t *pool)
188
*msg = "dup two strings, then compare";
193
150
a = svn_stringbuf_create(phrase_1, pool);
194
151
b = svn_stringbuf_create(phrase_2, pool);
195
152
c = svn_stringbuf_dup(a, pool);
284
217
static svn_error_t *
285
test10(const char **msg,
286
svn_boolean_t msg_only,
287
svn_test_opts_t *opts,
218
test10(apr_pool_t *pool)
290
220
svn_stringbuf_t *s, *t;
291
221
size_t len_1 = 0;
293
222
size_t block_len_1 = 0;
294
223
size_t block_len_2 = 0;
296
*msg = "block initialization and growth";
301
225
s = svn_stringbuf_create("a small string", pool);
302
226
len_1 = (s->len);
303
227
block_len_1 = (s->blocksize);
305
229
t = svn_stringbuf_create(", plus a string more than twice as long", pool);
306
230
svn_stringbuf_appendstr(s, t);
308
231
block_len_2 = (s->blocksize);
311
* - The initial block was just the right fit.
234
* - The initial block was at least the right fit.
235
* - The initial block was not excessively large.
312
236
* - The block more than doubled (because second string so long).
313
* - The block grew by a power of 2.
315
if ((len_1 == (block_len_1 - 1))
316
&& ((block_len_2 / block_len_1) > 2)
317
&& (((block_len_2 / block_len_1) % 2) == 0))
238
if ((len_1 <= (block_len_1 - 1))
239
&& ((block_len_1 - len_1) <= APR_ALIGN_DEFAULT(1))
240
&& ((block_len_2 / block_len_1) > 2))
318
241
return SVN_NO_ERROR;
320
243
return fail(pool, "test failed");
401
313
"if any of the Subversion platfoms will mangle them! There's no"
402
314
"need to test newline handling here anyway, it's not relevant.";
404
*msg = "create string from file";
409
316
status = apr_file_open(&file, fname, APR_WRITE | APR_TRUNCATE | APR_CREATE,
410
317
APR_OS_DEFAULT, pool);
488
391
static svn_error_t *
489
test13(const char **msg,
490
svn_boolean_t msg_only,
491
svn_test_opts_t *opts,
392
test13(apr_pool_t *pool)
494
*msg = "find_char_backward; middle case";
495
394
a = svn_stringbuf_create("test, test", pool);
498
test_find_char_backward(a->data, a->len, ',', 4, msg_only, pool);
396
return test_find_char_backward(a->data, a->len, ',', 4, pool);
501
399
static svn_error_t *
502
test14(const char **msg,
503
svn_boolean_t msg_only,
504
svn_test_opts_t *opts,
400
test14(apr_pool_t *pool)
507
*msg = "find_char_backward; 0 case";
509
402
a = svn_stringbuf_create(",test test", pool);
512
test_find_char_backward(a->data, a->len, ',', 0, msg_only, pool);
404
return test_find_char_backward(a->data, a->len, ',', 0, pool);
515
407
static svn_error_t *
516
test15(const char **msg,
517
svn_boolean_t msg_only,
518
svn_test_opts_t *opts,
408
test15(apr_pool_t *pool)
521
*msg = "find_char_backward; strlen - 1 case";
523
410
a = svn_stringbuf_create("testing,", pool);
525
412
return test_find_char_backward(a->data,
533
419
static svn_error_t *
534
test16(const char **msg,
535
svn_boolean_t msg_only,
536
svn_test_opts_t *opts,
420
test16(apr_pool_t *pool)
539
*msg = "find_char_backward; len = 0 case";
541
422
a = svn_stringbuf_create("", pool);
544
test_find_char_backward(a->data, a->len, ',', 0, msg_only, pool);
424
return test_find_char_backward(a->data, a->len, ',', 0, pool);
547
427
static svn_error_t *
548
test17(const char **msg,
549
svn_boolean_t msg_only,
550
svn_test_opts_t *opts,
428
test17(apr_pool_t *pool)
553
*msg = "find_char_backward; no occurence case";
555
430
a = svn_stringbuf_create("test test test", pool);
557
432
return test_find_char_backward(a->data,
565
439
static svn_error_t *
566
440
test_first_non_whitespace(const char *str,
567
441
const apr_size_t pos,
568
svn_boolean_t msg_only,
569
442
apr_pool_t *pool)
576
446
a = svn_stringbuf_create(str, pool);
578
448
i = svn_stringbuf_first_non_whitespace(a);
586
456
static svn_error_t *
587
test18(const char **msg,
588
svn_boolean_t msg_only,
589
svn_test_opts_t *opts,
592
*msg = "check whitespace removal; common case";
594
return test_first_non_whitespace(" \ttest", 4, msg_only, pool);
598
test19(const char **msg,
599
svn_boolean_t msg_only,
600
svn_test_opts_t *opts,
603
*msg = "check whitespace removal; no whitespace case";
605
return test_first_non_whitespace("test", 0, msg_only, pool);
609
test20(const char **msg,
610
svn_boolean_t msg_only,
611
svn_test_opts_t *opts,
614
*msg = "check whitespace removal; all whitespace case";
616
return test_first_non_whitespace(" ", 3, msg_only, pool);
620
test21(const char **msg,
621
svn_boolean_t msg_only,
622
svn_test_opts_t *opts,
625
*msg = "check that whitespace will be stripped correctly";
457
test18(apr_pool_t *pool)
459
return test_first_non_whitespace(" \ttest", 4, pool);
463
test19(apr_pool_t *pool)
465
return test_first_non_whitespace("test", 0, pool);
469
test20(apr_pool_t *pool)
471
return test_first_non_whitespace(" ", 3, pool);
475
test21(apr_pool_t *pool)
630
477
a = svn_stringbuf_create(" \ttest\t\t \t ", pool);
631
478
b = svn_stringbuf_create("test", pool);
659
502
static svn_error_t *
660
test22(const char **msg,
661
svn_boolean_t msg_only,
662
svn_test_opts_t *opts,
503
test22(apr_pool_t *pool)
665
*msg = "compare stringbufs; different lengths";
667
return test_stringbuf_unequal("abc", "abcd", msg_only, pool);
505
return test_stringbuf_unequal("abc", "abcd", pool);
670
508
static svn_error_t *
671
test23(const char **msg,
672
svn_boolean_t msg_only,
673
svn_test_opts_t *opts,
509
test23(apr_pool_t *pool)
676
*msg = "compare stringbufs; same length, different content";
678
return test_stringbuf_unequal("abc", "abb", msg_only, pool);
511
return test_stringbuf_unequal("abc", "abb", pool);
689
522
struct svn_test_descriptor_t test_funcs[] =
692
SVN_TEST_PASS(test1),
693
SVN_TEST_PASS(test2),
694
SVN_TEST_PASS(test3),
695
SVN_TEST_PASS(test4),
696
SVN_TEST_PASS(test5),
697
SVN_TEST_PASS(test6),
698
SVN_TEST_PASS(test7),
699
SVN_TEST_PASS(test8),
700
SVN_TEST_PASS(test9),
701
SVN_TEST_PASS(test10),
702
SVN_TEST_PASS(test11),
703
SVN_TEST_PASS(test12),
704
SVN_TEST_PASS(test13),
705
SVN_TEST_PASS(test14),
706
SVN_TEST_PASS(test15),
707
SVN_TEST_PASS(test16),
708
SVN_TEST_PASS(test17),
709
SVN_TEST_PASS(test18),
710
SVN_TEST_PASS(test19),
711
SVN_TEST_PASS(test20),
712
SVN_TEST_PASS(test21),
713
SVN_TEST_PASS(test22),
714
SVN_TEST_PASS(test23),
525
SVN_TEST_PASS2(test1,
526
"make svn_stringbuf_t from cstring"),
527
SVN_TEST_PASS2(test2,
528
"make svn_stringbuf_t from substring of cstring"),
529
SVN_TEST_PASS2(test3,
530
"append svn_stringbuf_t to svn_stringbuf_t"),
531
SVN_TEST_PASS2(test4,
532
"append C string to svn_stringbuf_t"),
533
SVN_TEST_PASS2(test5,
534
"append bytes, then compare two strings"),
535
SVN_TEST_PASS2(test6,
536
"dup two strings, then compare"),
537
SVN_TEST_PASS2(test7,
538
"chopping a string"),
539
SVN_TEST_PASS2(test8,
540
"emptying a string"),
541
SVN_TEST_PASS2(test9,
542
"fill string with hashmarks"),
543
SVN_TEST_PASS2(test10,
544
"block initialization and growth"),
545
SVN_TEST_PASS2(test11,
546
"formatting strings from varargs"),
547
SVN_TEST_PASS2(test12,
548
"create string from file"),
549
SVN_TEST_PASS2(test13,
550
"find_char_backward; middle case"),
551
SVN_TEST_PASS2(test14,
552
"find_char_backward; 0 case"),
553
SVN_TEST_PASS2(test15,
554
"find_char_backward; strlen - 1 case"),
555
SVN_TEST_PASS2(test16,
556
"find_char_backward; len = 0 case"),
557
SVN_TEST_PASS2(test17,
558
"find_char_backward; no occurence case"),
559
SVN_TEST_PASS2(test18,
560
"check whitespace removal; common case"),
561
SVN_TEST_PASS2(test19,
562
"check whitespace removal; no whitespace case"),
563
SVN_TEST_PASS2(test20,
564
"check whitespace removal; all whitespace case"),
565
SVN_TEST_PASS2(test21,
566
"check that whitespace will be stripped correctly"),
567
SVN_TEST_PASS2(test22,
568
"compare stringbufs; different lengths"),
569
SVN_TEST_PASS2(test23,
570
"compare stringbufs; same length, different content"),