root/lib/util/tests/str.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. test_string_sub_simple
  2. test_string_sub_multiple
  3. test_string_sub_longer
  4. test_string_sub_shorter
  5. test_string_sub_special_char
  6. test_string_sub_talloc_simple
  7. test_string_sub_talloc_multiple
  8. torture_local_util_str

   1 /* 
   2    Unix SMB/CIFS implementation.
   3 
   4    util_str testing
   5 
   6    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
   7    
   8    This program is free software; you can redistribute it and/or modify
   9    it under the terms of the GNU General Public License as published by
  10    the Free Software Foundation; either version 3 of the License, or
  11    (at your option) any later version.
  12    
  13    This program is distributed in the hope that it will be useful,
  14    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16    GNU General Public License for more details.
  17    
  18    You should have received a copy of the GNU General Public License
  19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20 */
  21 
  22 #include "includes.h"
  23 #include "torture/torture.h"
  24 
  25 static bool test_string_sub_simple(struct torture_context *tctx)
     /* [<][>][^][v][top][bottom][index][help] */
  26 {
  27         char tmp[100];
  28         safe_strcpy(tmp, "foobar", sizeof(tmp));
  29         string_sub(tmp, "foo", "bar", sizeof(tmp));
  30         torture_assert_str_equal(tctx, tmp, "barbar", "invalid sub");
  31         return true;
  32 }
  33 
  34 static bool test_string_sub_multiple(struct torture_context *tctx)
     /* [<][>][^][v][top][bottom][index][help] */
  35 {
  36         char tmp[100];
  37         safe_strcpy(tmp, "fooblafoo", sizeof(tmp));
  38         string_sub(tmp, "foo", "bar", sizeof(tmp));
  39         torture_assert_str_equal(tctx, tmp, "barblabar", "invalid sub");
  40         return true;
  41 }
  42 
  43 static bool test_string_sub_longer(struct torture_context *tctx)
     /* [<][>][^][v][top][bottom][index][help] */
  44 {
  45         char tmp[100];
  46         safe_strcpy(tmp, "foobla", sizeof(tmp));
  47         string_sub(tmp, "foo", "blie", sizeof(tmp));
  48         torture_assert_str_equal(tctx, tmp, "bliebla", "invalid sub");
  49         return true;
  50 }
  51 
  52 static bool test_string_sub_shorter(struct torture_context *tctx)
     /* [<][>][^][v][top][bottom][index][help] */
  53 {
  54         char tmp[100];
  55         safe_strcpy(tmp, "foobla", sizeof(tmp));
  56         string_sub(tmp, "foo", "bl", sizeof(tmp));
  57         torture_assert_str_equal(tctx, tmp, "blbla", "invalid sub");
  58         return true;
  59 }
  60 
  61 static bool test_string_sub_special_char(struct torture_context *tctx)
     /* [<][>][^][v][top][bottom][index][help] */
  62 {
  63         char tmp[100];
  64         safe_strcpy(tmp, "foobla", sizeof(tmp));
  65         string_sub(tmp, "foo", "%b;l", sizeof(tmp));
  66         torture_assert_str_equal(tctx, tmp, "_b_lbla", "invalid sub");
  67         return true;
  68 }
  69 
  70 static bool test_string_sub_talloc_simple(struct torture_context *tctx)
     /* [<][>][^][v][top][bottom][index][help] */
  71 {
  72         char *t;
  73         
  74         t = string_sub_talloc(tctx, "foobla", "foo", "bl");
  75 
  76         torture_assert_str_equal(tctx, t, "blbla", "invalid sub");
  77 
  78         return true;
  79 }
  80 
  81 static bool test_string_sub_talloc_multiple(struct torture_context *tctx)
     /* [<][>][^][v][top][bottom][index][help] */
  82 {
  83         char *t;
  84         
  85         t = string_sub_talloc(tctx, "fooblafoo", "foo", "aapnootmies");
  86 
  87         torture_assert_str_equal(tctx, t, "aapnootmiesblaaapnootmies", 
  88                                  "invalid sub");
  89 
  90         return true;
  91 }
  92 
  93 
  94 
  95 struct torture_suite *torture_local_util_str(TALLOC_CTX *mem_ctx)
     /* [<][>][^][v][top][bottom][index][help] */
  96 {
  97         struct torture_suite *suite = torture_suite_create(mem_ctx, "STR");
  98 
  99         torture_suite_add_simple_test(suite, "string_sub_simple", 
 100                                       test_string_sub_simple);
 101 
 102         torture_suite_add_simple_test(suite, "string_sub_multiple", 
 103                                       test_string_sub_multiple);
 104 
 105         torture_suite_add_simple_test(suite, "string_sub_shorter", 
 106                                       test_string_sub_shorter);
 107 
 108         torture_suite_add_simple_test(suite, "string_sub_longer", 
 109                                       test_string_sub_longer);
 110 
 111         torture_suite_add_simple_test(suite, "string_sub_special_chars", 
 112                                       test_string_sub_special_char);
 113 
 114         torture_suite_add_simple_test(suite, "string_sub_talloc_simple", 
 115                                       test_string_sub_talloc_simple);
 116 
 117         torture_suite_add_simple_test(suite, "string_sub_talloc_multiple", 
 118                                       test_string_sub_talloc_multiple);
 119 
 120         return suite;
 121 }

/* [<][>][^][v][top][bottom][index][help] */