Ignore:
Timestamp:
Dec 19, 2006, 10:01:59 PM (18 years ago)
Author:
rainer
Message:

Fix for ticket #38 (csv escaping) and #39 (building on cygwin). Also optimize a bit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cutest_sh_utils.c

    r68 r76  
    66#include "samhain.h"
    77#include "sh_utils.h"
     8
     9void Test_sl_strlcpy (CuTest *tc) {
     10  int ret;
     11  char out[] = "aaaaaa";
     12  char in[]  = "bbb";
     13
     14  ret = sl_strlcpy (NULL, NULL, 0);
     15  CuAssertIntEquals(tc, ret, SL_ENONE);
     16
     17  ret = sl_strlcpy (NULL, in, 0);
     18  CuAssertIntEquals(tc, ret, SL_ENULL);
     19
     20  ret = sl_strlcpy (out, NULL, 0);
     21  CuAssertIntEquals(tc, ret, SL_ENONE);
     22
     23  ret = sl_strlcpy (out, in, 0);
     24  CuAssertIntEquals(tc, ret, SL_ENONE);
     25
     26  ret = sl_strlcpy (out, NULL, 7);
     27  CuAssertIntEquals(tc, ret, SL_ENONE);
     28  CuAssertStrEquals(tc, "", out);
     29
     30  out[0] = 'a';
     31  ret = sl_strlcpy (out, in, 4);
     32  CuAssertIntEquals(tc, ret, SL_ENONE);
     33  CuAssertStrEquals(tc, "bbb", out);
     34  CuAssertStrEquals(tc, "aa", &out[4]);
     35 
     36  return;
     37}
     38
     39void Test_sl_strlcat (CuTest *tc) {
     40  int ret;
     41  char out[16] = "aaaaaa";
     42  char in[16]  = "bbb";
     43
     44  ret = sl_strlcat (NULL, NULL, 0);
     45  CuAssertIntEquals(tc, ret, SL_ENONE);
     46
     47  ret = sl_strlcat (NULL, in, 0);
     48  CuAssertIntEquals(tc, ret, SL_ENONE);
     49
     50  ret = sl_strlcat (out, NULL, 0);
     51  CuAssertIntEquals(tc, ret, SL_ENONE);
     52
     53  ret = sl_strlcat (out, in, 0);
     54  CuAssertIntEquals(tc, ret, SL_ENONE);
     55
     56  ret = sl_strlcat (out, NULL, sizeof(out));
     57  CuAssertIntEquals(tc, ret, SL_ENONE);
     58  CuAssertStrEquals(tc, "aaaaaa", out);
     59
     60  ret = sl_strlcat (out, in, 7);
     61  CuAssertIntEquals(tc, ret, SL_ETRUNC);
     62  CuAssertStrEquals(tc, "aaaaaa", out);
     63
     64  ret = sl_strlcat (out, in, 8);
     65  CuAssertIntEquals(tc, ret, SL_ETRUNC);
     66  CuAssertStrEquals(tc, "aaaaaab", out);
     67
     68  ret = sl_strlcat (out, in, sizeof(out));
     69  CuAssertIntEquals(tc, ret, SL_ENONE);
     70  CuAssertStrEquals(tc, "aaaaaabbbb", out);
     71
     72  CuAssertStrEquals(tc, "bbb", in);
     73
     74  return;
     75}
    876
    977void Test_sh_util_acl_compact (CuTest *tc) {
     
    238306  CuAssertIntEquals(tc, ret, S_FALSE);
    239307
     308  /* switch on utf8 checking for sh_util_obscurename() */
     309
     310  ret = sh_util_obscure_utf8("Y");
     311  CuAssertIntEquals(tc, ret, 0);
    240312
    241313  ret = sh_util_obscure_ok ("0x01,0x02,0x03");
     
    244316  ret = sh_util_valid_utf8 (input);
    245317  CuAssertIntEquals(tc, ret, S_TRUE);
     318  ret = sh_util_obscurename (0, (char *)input, S_FALSE /* no log message */);
     319  CuAssertIntEquals(tc, ret, 0);
    246320
    247321  input[0] = '\t';
    248322  ret = sh_util_valid_utf8 (input);
    249323  CuAssertIntEquals(tc, ret, S_FALSE);
     324  ret = sh_util_obscurename (0, (char *)input, S_FALSE /* no log message */);
     325  CuAssertIntEquals(tc, ret, -1);
    250326
    251327  input[0] = 0x01;
    252328  ret = sh_util_valid_utf8 (input);
    253329  CuAssertIntEquals(tc, ret, S_TRUE);
     330  ret = sh_util_obscurename (0, (char *)input, S_FALSE /* no log message */);
     331  CuAssertIntEquals(tc, ret, 0);
    254332
    255333  input[0] = 0x02;
    256334  ret = sh_util_valid_utf8 (input);
    257335  CuAssertIntEquals(tc, ret, S_TRUE);
     336  ret = sh_util_obscurename (0, (char *)input, S_FALSE /* no log message */);
     337  CuAssertIntEquals(tc, ret, 0);
    258338
    259339  input[0] = 0x03;
    260340  ret = sh_util_valid_utf8 (input);
    261341  CuAssertIntEquals(tc, ret, S_TRUE);
     342  ret = sh_util_obscurename (0, (char *)input, S_FALSE /* no log message */);
     343  CuAssertIntEquals(tc, ret, 0);
    262344
    263345  input[0] = 0x04;
    264346  ret = sh_util_valid_utf8 (input);
    265347  CuAssertIntEquals(tc, ret, S_FALSE);
     348  ret = sh_util_obscurename (0, (char *)input, S_FALSE /* no log message */);
     349  CuAssertIntEquals(tc, ret, -1);
     350
     351  input[0] = 'f';
     352  ret = sh_util_valid_utf8 (input);
     353  CuAssertIntEquals(tc, ret, S_TRUE);
     354  ret = sh_util_obscurename (0, (char *)input, S_FALSE /* no log message */);
     355  CuAssertIntEquals(tc, ret, 0);
     356
     357  input[5] = ' ';
     358  ret = sh_util_valid_utf8 (input);
     359  CuAssertIntEquals(tc, ret, S_FALSE);
     360  ret = sh_util_obscurename (0, (char *)input, S_FALSE /* no log message */);
     361  CuAssertIntEquals(tc, ret, -1);
     362
     363  input[5] = 'r'; input[3] = ' ';
     364  ret = sh_util_valid_utf8 (input);
     365  CuAssertIntEquals(tc, ret, S_TRUE);
     366  ret = sh_util_obscurename (0, (char *)input, S_FALSE /* no log message */);
     367  CuAssertIntEquals(tc, ret, 0);
    266368
    267369
     
    277379  char input[16] = "foobar";
    278380
     381  /* switch off utf8 checking for sh_util_obscurename() */
     382
     383  ret = sh_util_obscure_utf8("N");
     384  CuAssertIntEquals(tc, ret, 0);
     385
    279386  ret = sh_util_obscure_ok ("0xA1,0xA2,0xA3");
    280387  CuAssertIntEquals(tc, ret, 0);
     
    303410  CuAssertIntEquals(tc, ret, -1);
    304411
     412  input[0] = 'f';
     413  ret = sh_util_obscurename (0, input, S_FALSE /* no log message */);
     414  CuAssertIntEquals(tc, ret, 0);
     415
     416  input[5] = ' ';
     417  ret = sh_util_obscurename (0, input, S_FALSE /* no log message */);
     418  CuAssertIntEquals(tc, ret, -1);
     419
     420  input[5] = 'r'; input[3] = ' ';
     421  ret = sh_util_obscurename (0, input, S_FALSE /* no log message */);
     422  CuAssertIntEquals(tc, ret, 0);
    305423#else
    306424  CuAssertIntEquals(tc, ret, 0);
Note: See TracChangeset for help on using the changeset viewer.