aboutsummaryrefslogtreecommitdiff
path: root/3rdparty/dict/dict-test.c
blob: 80cf847b829942c495b99ce38ad1cd4aede311de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* ******************************************** */
/* File Name: dict-test.c                       */
/* Author: (C) 2008-2009 - Juan Jos� Ponteprino */
/* Description: Dictionary API Headers          */
/* License: This code is licenced as LGPL       */
/* ******************************************** */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dict.h>

int main( int argc, char * argv[] )
{
    DICT_T * main_dict = NULL;
    char * val1 = "hello world";
    char * val2 = "goodbye world";
    char * val3 = "works!";

    DICT_Init();

    main_dict = DICT_Create( "main" );
    if ( !main_dict )
    {
        fprintf( stderr, "Can't create dictionary\n" );
        exit( -1 );
    }

    printf( "\n" );
    printf( "Add a new entry... foo1... ret: %d\n", DICT_AddEntry( main_dict, "foo1", ( void * ) val1, strlen( val1 ) + 1, DICT_ENTRY_FLAG_NORMAL ));

    printf( "\n" );
    printf( "Get an exists entry... foo1... ret: [%s]\n", DICT_GetEntry( main_dict, "foo1", NULL ));
    printf( "Get non exist entry... foo2... ret: [%s]\n", DICT_GetEntry( main_dict, "foo2", NULL ));

    printf( "\n" );
    printf( "Find an entry... foo1... ret: %p\n", DICT_FindEntry( main_dict, "foo1" ) );
    printf( "Find non exists entry... foo2... ret: %p\n", DICT_FindEntry( main_dict, "foo2" ) );

    printf( "\n" );
    printf( "Update an exists entry... foo1... ret: %d\n", DICT_AddEntry( main_dict, "foo1", ( void * ) val2, strlen( val2 ) + 1, DICT_ENTRY_FLAG_NORMAL ));

    printf( "\n" );
    printf( "Get an exists entry (with a large value)... foo1... ret: [%s]\n", DICT_GetEntry( main_dict, "foo1", NULL ));
    printf( "Find an entry... foo1... ret: %p\n", DICT_FindEntry( main_dict, "foo1" ) );

    printf( "\n" );
    printf( "Update an exists entry (with a short value)... foo1... ret: %d\n", DICT_AddEntry( main_dict, "foo1", ( void * ) val3, strlen( val3 ) + 1, DICT_ENTRY_FLAG_NORMAL ));

    printf( "\n" );
    printf( "Get an exists entry... foo1... ret: [%s]\n", DICT_GetEntry( main_dict, "foo1", NULL ));
    printf( "Find an entry... foo1... ret: %p\n", DICT_FindEntry( main_dict, "foo1" ) );

    printf( "\n" );
    printf( "Delete an exists entry...\n" );
    DICT_DelEntry( main_dict, "foo1" );

    printf( "\n" );
    printf( "Delete a non exists entry...\n" );
    DICT_DelEntry( main_dict, "foo1" );

    printf( "\n" );
    printf( "Get a non exists entry... foo1... ret: %p\n", DICT_GetEntry( main_dict, "foo1", NULL ));
    printf( "Find a non exists entry... foo1... ret: [%s]\n", DICT_FindEntry( main_dict, "foo1" ));

    printf( "\n" );
    printf( "Add a new entry... foo1... ret: %d\n", DICT_AddEntry( main_dict, "foo1", ( void * ) val1, strlen( val1 ) + 1, DICT_ENTRY_FLAG_NORMAL ));
    printf( "Add a new entry... foo2... ret: %d\n", DICT_AddEntry( main_dict, "foo2", ( void * ) val2, strlen( val2 ) + 1, DICT_ENTRY_FLAG_NORMAL ));
    printf( "Add a new entry... foo3... ret: %d\n", DICT_AddEntry( main_dict, "foo3", ( void * ) val3, strlen( val3 ) + 1, DICT_ENTRY_FLAG_NORMAL ));

    printf( "\n" );
    printf( "Display all Entries\n" );
    DICT_ShowAllEntries( main_dict, stdout );

    printf( "\n" );
    printf( "Delete all Entries\n" );
    DICT_DelAllEntries( main_dict );

    printf( "\n" );
    printf( "Display all Entries\n" );
    DICT_ShowAllEntries( main_dict, stdout );

    DICT_Destroy( main_dict );

    DICT_Exit();

    return 0;
}