~ubuntu-branches/ubuntu/trusty/subversion/trusty-proposed

« back to all changes in this revision

Viewing changes to subversion/tests/libsvn_subr/string-test.c

  • Committer: Package Import Robot
  • Author(s): Andy Whitcroft
  • Date: 2012-06-21 15:36:36 UTC
  • mfrom: (0.4.13 sid)
  • Revision ID: package-import@ubuntu.com-20120621153636-amqqmuidgwgxz1ly
Tags: 1.7.5-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Create pot file on build.
  - Build a python-subversion-dbg package.
  - Build-depend on python-dbg.
  - Build-depend on default-jre-headless/-jdk.
  - Do not apply java-build patch.
  - debian/rules: Manually create the doxygen output directory, otherwise
    we get weird build failures when running parallel builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * string-test.c:  a collection of libsvn_string tests
3
3
 *
4
4
 * ====================================================================
5
 
 * Copyright (c) 2000-2004, 2008 CollabNet.  All rights reserved.
6
 
 *
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.
12
 
 *
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
 
12
 *
 
13
 *      http://www.apache.org/licenses/LICENSE-2.0
 
14
 *
 
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
 
20
 *    under the License.
16
21
 * ====================================================================
17
22
 */
18
23
 
61
66
 
62
67
 
63
68
static svn_error_t *
64
 
test1(const char **msg,
65
 
      svn_boolean_t msg_only,
66
 
      svn_test_opts_t *opts,
67
 
      apr_pool_t *pool)
 
69
test1(apr_pool_t *pool)
68
70
{
69
 
  *msg = "make svn_stringbuf_t from cstring";
70
 
 
71
 
  if (msg_only)
72
 
    return SVN_NO_ERROR;
73
 
 
74
71
  a = svn_stringbuf_create(phrase_1, pool);
75
72
 
76
73
  /* Test that length, data, and null-termination are correct. */
82
79
 
83
80
 
84
81
static svn_error_t *
85
 
test2(const char **msg,
86
 
      svn_boolean_t msg_only,
87
 
      svn_test_opts_t *opts,
88
 
      apr_pool_t *pool)
 
82
test2(apr_pool_t *pool)
89
83
{
90
 
  *msg = "make svn_stringbuf_t from substring of cstring";
91
 
 
92
 
  if (msg_only)
93
 
    return SVN_NO_ERROR;
94
 
 
95
84
  b = svn_stringbuf_ncreate(phrase_2, 16, pool);
96
85
 
97
86
  /* Test that length, data, and null-termination are correct. */
103
92
 
104
93
 
105
94
static svn_error_t *
106
 
test3(const char **msg,
107
 
      svn_boolean_t msg_only,
108
 
      svn_test_opts_t *opts,
109
 
      apr_pool_t *pool)
 
95
test3(apr_pool_t *pool)
110
96
{
111
97
  char *tmp;
112
98
  size_t old_len;
113
99
 
114
 
  *msg = "append svn_stringbuf_t to svn_stringbuf_t";
115
 
 
116
 
  if (msg_only)
117
 
    return SVN_NO_ERROR;
118
 
 
119
100
  a = svn_stringbuf_create(phrase_1, pool);
120
101
  b = svn_stringbuf_ncreate(phrase_2, 16, pool);
121
102
 
134
115
 
135
116
 
136
117
static svn_error_t *
137
 
test4(const char **msg,
138
 
      svn_boolean_t msg_only,
139
 
      svn_test_opts_t *opts,
140
 
      apr_pool_t *pool)
 
118
test4(apr_pool_t *pool)
141
119
{
142
 
  *msg = "append C string to svn_stringbuf_t";
143
 
 
144
 
  if (msg_only)
145
 
    return SVN_NO_ERROR;
146
 
 
147
120
  a = svn_stringbuf_create(phrase_1, pool);
148
121
  svn_stringbuf_appendcstr(a, "new bytes to append");
149
122
 
157
130
 
158
131
 
159
132
static svn_error_t *
160
 
test5(const char **msg,
161
 
      svn_boolean_t msg_only,
162
 
      svn_test_opts_t *opts,
163
 
      apr_pool_t *pool)
 
133
test5(apr_pool_t *pool)
164
134
{
165
 
  *msg = "append bytes, then compare two strings";
166
 
 
167
 
  if (msg_only)
168
 
    return SVN_NO_ERROR;
169
 
 
170
135
  a = svn_stringbuf_create(phrase_1, pool);
171
136
  svn_stringbuf_appendbytes(a, "new bytes to append", 9);
172
137
 
180
145
 
181
146
 
182
147
static svn_error_t *
183
 
test6(const char **msg,
184
 
      svn_boolean_t msg_only,
185
 
      svn_test_opts_t *opts,
186
 
      apr_pool_t *pool)
 
148
test6(apr_pool_t *pool)
187
149
{
188
 
  *msg = "dup two strings, then compare";
189
 
 
190
 
  if (msg_only)
191
 
    return SVN_NO_ERROR;
192
 
 
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);
203
160
 
204
161
 
205
162
static svn_error_t *
206
 
test7(const char **msg,
207
 
      svn_boolean_t msg_only,
208
 
      svn_test_opts_t *opts,
209
 
      apr_pool_t *pool)
 
163
test7(apr_pool_t *pool)
210
164
{
211
165
  char *tmp;
212
166
  size_t tmp_len;
213
167
 
214
 
  *msg = "chopping a string";
215
 
 
216
 
  if (msg_only)
217
 
    return SVN_NO_ERROR;
218
 
 
219
168
  c = svn_stringbuf_create(phrase_2, pool);
220
169
 
221
170
  tmp_len = c->len;
234
183
 
235
184
 
236
185
static svn_error_t *
237
 
test8(const char **msg,
238
 
      svn_boolean_t msg_only,
239
 
      svn_test_opts_t *opts,
240
 
      apr_pool_t *pool)
 
186
test8(apr_pool_t *pool)
241
187
{
242
 
  *msg = "emptying a string";
243
 
 
244
 
  if (msg_only)
245
 
    return SVN_NO_ERROR;
246
 
 
247
188
  c = svn_stringbuf_create(phrase_2, pool);
248
189
 
249
190
  svn_stringbuf_setempty(c);
256
197
 
257
198
 
258
199
static svn_error_t *
259
 
test9(const char **msg,
260
 
      svn_boolean_t msg_only,
261
 
      svn_test_opts_t *opts,
262
 
      apr_pool_t *pool)
 
200
test9(apr_pool_t *pool)
263
201
{
264
 
  *msg = "fill string with hashmarks";
265
 
 
266
 
  if (msg_only)
267
 
    return SVN_NO_ERROR;
268
 
 
269
202
  a = svn_stringbuf_create(phrase_1, pool);
270
203
 
271
204
  svn_stringbuf_fillchar(a, '#');
282
215
 
283
216
 
284
217
static svn_error_t *
285
 
test10(const char **msg,
286
 
       svn_boolean_t msg_only,
287
 
       svn_test_opts_t *opts,
288
 
       apr_pool_t *pool)
 
218
test10(apr_pool_t *pool)
289
219
{
290
220
  svn_stringbuf_t *s, *t;
291
221
  size_t len_1 = 0;
292
 
  size_t len_2 = 0;
293
222
  size_t block_len_1 = 0;
294
223
  size_t block_len_2 = 0;
295
224
 
296
 
  *msg = "block initialization and growth";
297
 
 
298
 
  if (msg_only)
299
 
    return SVN_NO_ERROR;
300
 
 
301
225
  s = svn_stringbuf_create("a small string", pool);
302
226
  len_1       = (s->len);
303
227
  block_len_1 = (s->blocksize);
304
228
 
305
229
  t = svn_stringbuf_create(", plus a string more than twice as long", pool);
306
230
  svn_stringbuf_appendstr(s, t);
307
 
  len_2       = (s->len);
308
231
  block_len_2 = (s->blocksize);
309
232
 
310
233
  /* Test that:
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.
314
237
   */
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;
319
242
  else
320
243
    return fail(pool, "test failed");
322
245
 
323
246
 
324
247
static svn_error_t *
325
 
test11(const char **msg,
326
 
       svn_boolean_t msg_only,
327
 
       svn_test_opts_t *opts,
328
 
       apr_pool_t *pool)
 
248
test11(apr_pool_t *pool)
329
249
{
330
250
  svn_stringbuf_t *s;
331
251
 
332
 
  *msg = "formatting strings from varargs";
333
 
 
334
 
  if (msg_only)
335
 
    return SVN_NO_ERROR;
336
 
 
337
252
  s = svn_stringbuf_createf(pool,
338
253
                            "This %s is used in test %d.",
339
254
                            "string",
385
300
 
386
301
 
387
302
static svn_error_t *
388
 
test12(const char **msg,
389
 
       svn_boolean_t msg_only,
390
 
       svn_test_opts_t *opts,
391
 
       apr_pool_t *pool)
 
303
test12(apr_pool_t *pool)
392
304
{
393
305
  svn_stringbuf_t *s;
394
306
  const char fname[] = "string-test.tmp";
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.";
403
315
 
404
 
  *msg = "create string from file";
405
 
 
406
 
  if (msg_only)
407
 
    return SVN_NO_ERROR;
408
 
 
409
316
  status = apr_file_open(&file, fname, APR_WRITE | APR_TRUNCATE | APR_CREATE,
410
317
                         APR_OS_DEFAULT, pool);
411
318
  if (status)
468
375
                        apr_size_t len,
469
376
                        char ch,
470
377
                        apr_size_t pos,
471
 
                        svn_boolean_t msg_only,
472
378
                        apr_pool_t *pool)
473
379
{
474
380
  apr_size_t i;
475
381
 
476
 
  if (msg_only)
477
 
    return SVN_NO_ERROR;
478
 
 
479
382
  a = svn_stringbuf_create(data, pool);
480
383
  i = svn_stringbuf_find_char_backward(a, ch);
481
384
 
486
389
}
487
390
 
488
391
static svn_error_t *
489
 
test13(const char **msg,
490
 
       svn_boolean_t msg_only,
491
 
       svn_test_opts_t *opts,
492
 
       apr_pool_t *pool)
 
392
test13(apr_pool_t *pool)
493
393
{
494
 
  *msg = "find_char_backward; middle case";
495
394
  a = svn_stringbuf_create("test, test", pool);
496
395
 
497
 
  return
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);
499
397
}
500
398
 
501
399
static svn_error_t *
502
 
test14(const char **msg,
503
 
       svn_boolean_t msg_only,
504
 
       svn_test_opts_t *opts,
505
 
       apr_pool_t *pool)
 
400
test14(apr_pool_t *pool)
506
401
{
507
 
  *msg = "find_char_backward; 0 case";
508
 
 
509
402
  a = svn_stringbuf_create(",test test", pool);
510
403
 
511
 
  return
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);
513
405
}
514
406
 
515
407
static svn_error_t *
516
 
test15(const char **msg,
517
 
       svn_boolean_t msg_only,
518
 
       svn_test_opts_t *opts,
519
 
       apr_pool_t *pool)
 
408
test15(apr_pool_t *pool)
520
409
{
521
 
  *msg = "find_char_backward; strlen - 1 case";
522
 
 
523
410
  a = svn_stringbuf_create("testing,", pool);
524
411
 
525
412
  return test_find_char_backward(a->data,
526
413
                                 a->len,
527
414
                                 ',',
528
415
                                 a->len - 1,
529
 
                                 msg_only,
530
416
                                 pool);
531
417
}
532
418
 
533
419
static svn_error_t *
534
 
test16(const char **msg,
535
 
       svn_boolean_t msg_only,
536
 
       svn_test_opts_t *opts,
537
 
       apr_pool_t *pool)
 
420
test16(apr_pool_t *pool)
538
421
{
539
 
  *msg = "find_char_backward; len = 0 case";
540
 
 
541
422
  a = svn_stringbuf_create("", pool);
542
423
 
543
 
  return
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);
545
425
}
546
426
 
547
427
static svn_error_t *
548
 
test17(const char **msg,
549
 
       svn_boolean_t msg_only,
550
 
       svn_test_opts_t *opts,
551
 
       apr_pool_t *pool)
 
428
test17(apr_pool_t *pool)
552
429
{
553
 
  *msg = "find_char_backward; no occurence case";
554
 
 
555
430
  a = svn_stringbuf_create("test test test", pool);
556
431
 
557
432
  return test_find_char_backward(a->data,
558
433
                                 a->len,
559
434
                                 ',',
560
435
                                 a->len,
561
 
                                 msg_only,
562
436
                                 pool);
563
437
}
564
438
 
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)
570
443
{
571
444
  apr_size_t i;
572
445
 
573
 
  if (msg_only)
574
 
    return SVN_NO_ERROR;
575
 
 
576
446
  a = svn_stringbuf_create(str, pool);
577
447
 
578
448
  i = svn_stringbuf_first_non_whitespace(a);
584
454
}
585
455
 
586
456
static svn_error_t *
587
 
test18(const char **msg,
588
 
       svn_boolean_t msg_only,
589
 
       svn_test_opts_t *opts,
590
 
       apr_pool_t *pool)
591
 
{
592
 
  *msg = "check whitespace removal; common case";
593
 
 
594
 
  return test_first_non_whitespace("   \ttest", 4, msg_only, pool);
595
 
}
596
 
 
597
 
static svn_error_t *
598
 
test19(const char **msg,
599
 
       svn_boolean_t msg_only,
600
 
       svn_test_opts_t *opts,
601
 
       apr_pool_t *pool)
602
 
{
603
 
  *msg = "check whitespace removal; no whitespace case";
604
 
 
605
 
  return test_first_non_whitespace("test", 0, msg_only, pool);
606
 
}
607
 
 
608
 
static svn_error_t *
609
 
test20(const char **msg,
610
 
       svn_boolean_t msg_only,
611
 
       svn_test_opts_t *opts,
612
 
       apr_pool_t *pool)
613
 
{
614
 
  *msg = "check whitespace removal; all whitespace case";
615
 
 
616
 
  return test_first_non_whitespace("   ", 3, msg_only, pool);
617
 
}
618
 
 
619
 
static svn_error_t *
620
 
test21(const char **msg,
621
 
       svn_boolean_t msg_only,
622
 
       svn_test_opts_t *opts,
623
 
       apr_pool_t *pool)
624
 
{
625
 
  *msg = "check that whitespace will be stripped correctly";
626
 
 
627
 
  if (msg_only)
628
 
    return SVN_NO_ERROR;
629
 
 
 
457
test18(apr_pool_t *pool)
 
458
{
 
459
  return test_first_non_whitespace("   \ttest", 4, pool);
 
460
}
 
461
 
 
462
static svn_error_t *
 
463
test19(apr_pool_t *pool)
 
464
{
 
465
  return test_first_non_whitespace("test", 0, pool);
 
466
}
 
467
 
 
468
static svn_error_t *
 
469
test20(apr_pool_t *pool)
 
470
{
 
471
  return test_first_non_whitespace("   ", 3, pool);
 
472
}
 
473
 
 
474
static svn_error_t *
 
475
test21(apr_pool_t *pool)
 
476
{
630
477
  a = svn_stringbuf_create("    \ttest\t\t  \t  ", pool);
631
478
  b = svn_stringbuf_create("test", pool);
632
479
 
641
488
static svn_error_t *
642
489
test_stringbuf_unequal(const char* str1,
643
490
                       const char* str2,
644
 
                       svn_boolean_t msg_only,
645
491
                       apr_pool_t *pool)
646
492
{
647
 
  if (msg_only)
648
 
    return SVN_NO_ERROR;
649
 
 
650
493
  a = svn_stringbuf_create(str1, pool);
651
494
  b = svn_stringbuf_create(str2, pool);
652
495
 
657
500
}
658
501
 
659
502
static svn_error_t *
660
 
test22(const char **msg,
661
 
       svn_boolean_t msg_only,
662
 
       svn_test_opts_t *opts,
663
 
       apr_pool_t *pool)
 
503
test22(apr_pool_t *pool)
664
504
{
665
 
  *msg = "compare stringbufs; different lengths";
666
 
 
667
 
  return test_stringbuf_unequal("abc", "abcd", msg_only, pool);
 
505
  return test_stringbuf_unequal("abc", "abcd", pool);
668
506
}
669
507
 
670
508
static svn_error_t *
671
 
test23(const char **msg,
672
 
       svn_boolean_t msg_only,
673
 
       svn_test_opts_t *opts,
674
 
       apr_pool_t *pool)
 
509
test23(apr_pool_t *pool)
675
510
{
676
 
  *msg = "compare stringbufs; same length, different content";
677
 
 
678
 
  return test_stringbuf_unequal("abc", "abb", msg_only, pool);
 
511
  return test_stringbuf_unequal("abc", "abb", pool);
679
512
}
680
513
 
681
514
/*
689
522
struct svn_test_descriptor_t test_funcs[] =
690
523
  {
691
524
    SVN_TEST_NULL,
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"),
715
571
    SVN_TEST_NULL
716
572
  };