2014-08-29 10:14:43 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <history.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
static int test = 0;
|
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
#define TASSERT( a ) { \
|
|
|
|
assert ( a ); \
|
|
|
|
printf ( "Test %i passed (%s)\n", ++test, # a ); \
|
2014-08-29 10:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *file = "text";
|
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
static void history_test ( void )
|
2014-08-29 10:14:43 +00:00
|
|
|
{
|
2015-07-28 20:14:21 +00:00
|
|
|
unlink ( file );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
|
|
|
// Empty list.
|
2015-07-28 20:14:21 +00:00
|
|
|
unsigned int length = 0;
|
|
|
|
char **retv = history_get_list ( file, &length );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( retv == NULL );
|
|
|
|
TASSERT ( length == 0 );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 19:54:08 +00:00
|
|
|
// 1 item
|
2015-07-28 20:14:21 +00:00
|
|
|
history_set ( file, "aap" );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
retv = history_get_list ( file, &length );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( retv != NULL );
|
|
|
|
TASSERT ( length == 1 );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( strcmp ( retv[0], "aap" ) == 0 );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
g_strfreev ( retv );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
|
|
|
// Remove entry
|
|
|
|
history_remove ( file, "aap" );
|
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
length = 0;
|
|
|
|
retv = history_get_list ( file, &length );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( retv == NULL );
|
|
|
|
TASSERT ( length == 0 );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 19:54:08 +00:00
|
|
|
// 2 items
|
2015-07-28 20:14:21 +00:00
|
|
|
history_set ( file, "aap" );
|
|
|
|
history_set ( file, "aap" );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
retv = history_get_list ( file, &length );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( retv != NULL );
|
|
|
|
TASSERT ( length == 1 );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( strcmp ( retv[0], "aap" ) == 0 );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
g_strfreev ( retv );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
for ( unsigned int in = length + 1; in < 26; in++ ) {
|
|
|
|
char *p = g_strdup_printf ( "aap%i", in );
|
|
|
|
printf ( "%s- %d\n", p, in );
|
|
|
|
history_set ( file, p );
|
|
|
|
retv = history_get_list ( file, &length );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( retv != NULL );
|
|
|
|
TASSERT ( length == ( in ) );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
g_strfreev ( retv );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
g_free ( p );
|
2014-08-29 10:14:43 +00:00
|
|
|
}
|
|
|
|
// Max 25 entries.
|
2015-07-28 20:14:21 +00:00
|
|
|
history_set ( file, "blaat" );
|
|
|
|
retv = history_get_list ( file, &length );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( retv != NULL );
|
|
|
|
TASSERT ( length == 25 );
|
2014-08-29 10:14:43 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
g_strfreev ( retv );
|
2014-08-29 13:17:57 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 18:58:17 +00:00
|
|
|
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
2014-08-29 13:17:57 +00:00
|
|
|
{
|
2015-07-28 20:14:21 +00:00
|
|
|
history_test ();
|
2014-08-29 13:17:57 +00:00
|
|
|
|
2014-08-29 10:14:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|