1
/* Copyright (c) 2007 Sam Trenholme
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
15
* This software is provided 'as is' with no guarantees of correctness or
16
* fitness for purpose.
20
#include "DwStr_functions.h"
23
/* This actually isn't a public function; we just have it declared here
24
* so we can compile w/o warnings when -Wall is used */
25
uint32_t dwh_hash_compress(dw_str *obj);
28
dw_str *test = 0, *c1 = 0, *c2 = 0, *c3 = 0;
30
test = dw_create(256);
32
printf("String creation failed.\n");
35
/* Add some strings to the function */
36
if(dw_qspush((uint8_t *)"Life",test) == -1) {
37
printf("Appending failed.\n");
42
if(dw_qspush((uint8_t *)"liberty",test) == -1) {
43
printf("Appending failed.\n");
48
if(dw_qspush((uint8_t *)"happiness",test) == -1) {
49
printf("Appending failed.\n");
54
/* Test dw_fetch_u16 */
55
printf("16-bit value at offsets 0 2 4 7: ");
56
printf("%d ",(unsigned int)dw_fetch_u16(test,0));
57
printf("%d ",(unsigned int)dw_fetch_u16(test,2));
58
printf("%d ",(unsigned int)dw_fetch_u16(test,4));
59
printf("%d\n",(unsigned int)dw_fetch_u16(test,7));
61
/* Test dw_copy and dw_substr */
62
printf("TEST: dw_copy and dw_substr\n");
64
c2 = dw_substr(test,-9,-1,0);
65
c3 = dw_substr(test,5,7,0);
71
printf("c1 hash: %x\n",(unsigned int)dwh_hash_compress(c1));
72
printf("c2 hash: %x\n",(unsigned int)dwh_hash_compress(c2));
73
printf("c3 hash: %x\n",(unsigned int)dwh_hash_compress(c3));
77
printf("TEST: dw_qspop\n");
95
dw_qrappend((uint8_t *)" \t test",c1,0);
105
printf("blank hash: %x\n",(unsigned int)dwh_hash_compress(c1));
106
c1->len = 1; /* Don't do this in production code! */
107
for(a = 0; a<16;a++) {
108
*(c1->str) = a; /* Again, not in production code! */
109
printf("hash of %d: %x\n",a,(unsigned int)dwh_hash_compress(c1));
112
/* Coding style requires that we always have the following part
113
* at the end of any function that allocates strings */