2017-04-15 06:32:05 -04:00
|
|
|
/*
|
|
|
|
* rofi
|
|
|
|
*
|
|
|
|
* MIT/X11 License
|
|
|
|
* Copyright © 2013-2017 Qball Cow <qball@gmpclient.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-08-29 06:14:43 -04:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <history.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-02-02 05:38:33 -05:00
|
|
|
static unsigned int test = 0;
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
#define TASSERT( a ) { \
|
|
|
|
assert ( a ); \
|
2019-02-02 05:17:50 -05:00
|
|
|
printf ( "Test %u passed (%s)\n", ++test, # a ); \
|
2014-08-29 06:14:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *file = "text";
|
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
static void history_test ( void )
|
2014-08-29 06:14:43 -04:00
|
|
|
{
|
2015-07-28 16:14:21 -04:00
|
|
|
unlink ( file );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
|
|
|
// Empty list.
|
2015-07-28 16:14:21 -04:00
|
|
|
unsigned int length = 0;
|
|
|
|
char **retv = history_get_list ( file, &length );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
TASSERT ( retv == NULL );
|
|
|
|
TASSERT ( length == 0 );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 15:54:08 -04:00
|
|
|
// 1 item
|
2015-07-28 16:14:21 -04:00
|
|
|
history_set ( file, "aap" );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
retv = history_get_list ( file, &length );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
TASSERT ( retv != NULL );
|
|
|
|
TASSERT ( length == 1 );
|
|
|
|
TASSERT ( strcmp ( retv[0], "aap" ) == 0 );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
g_strfreev ( retv );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
|
|
|
// Remove entry
|
|
|
|
history_remove ( file, "aap" );
|
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
length = 0;
|
|
|
|
retv = history_get_list ( file, &length );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
TASSERT ( retv == NULL );
|
|
|
|
TASSERT ( length == 0 );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 15:54:08 -04:00
|
|
|
// 2 items
|
2015-07-28 16:14:21 -04:00
|
|
|
history_set ( file, "aap" );
|
|
|
|
history_set ( file, "aap" );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
retv = history_get_list ( file, &length );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
TASSERT ( retv != NULL );
|
|
|
|
TASSERT ( length == 1 );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
TASSERT ( strcmp ( retv[0], "aap" ) == 0 );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
g_strfreev ( retv );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
for ( unsigned int in = length + 1; in < 26; in++ ) {
|
2019-02-02 05:53:33 -05:00
|
|
|
char *p = g_strdup_printf ( "aap%u", in );
|
|
|
|
printf ( "%s- %u\n", p, in );
|
2015-07-28 16:14:21 -04:00
|
|
|
history_set ( file, p );
|
|
|
|
retv = history_get_list ( file, &length );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
TASSERT ( retv != NULL );
|
|
|
|
TASSERT ( length == ( in ) );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
g_strfreev ( retv );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
g_free ( p );
|
2014-08-29 06:14:43 -04:00
|
|
|
}
|
|
|
|
// Max 25 entries.
|
2015-07-28 16:14:21 -04:00
|
|
|
history_set ( file, "blaat" );
|
|
|
|
retv = history_get_list ( file, &length );
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
TASSERT ( retv != NULL );
|
|
|
|
TASSERT ( length == 25 );
|
2016-04-10 07:55:18 -04:00
|
|
|
for ( unsigned int in = 0; in < 24; in++ ) {
|
2016-04-10 08:30:13 -04:00
|
|
|
char *p = g_strdup_printf ( "aap%i", in + 2 );
|
|
|
|
TASSERT ( g_strcmp0 ( retv[in], p ) == 0 );
|
2016-04-10 07:55:18 -04:00
|
|
|
|
|
|
|
g_free ( p );
|
|
|
|
}
|
2014-08-29 06:14:43 -04:00
|
|
|
|
2015-07-28 16:14:21 -04:00
|
|
|
g_strfreev ( retv );
|
2016-02-21 06:57:30 -05:00
|
|
|
|
|
|
|
unlink ( file );
|
2014-08-29 09:17:57 -04:00
|
|
|
}
|
|
|
|
|
2021-08-14 07:03:16 -04:00
|
|
|
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
2014-08-29 09:17:57 -04:00
|
|
|
{
|
2015-07-28 16:14:21 -04:00
|
|
|
history_test ();
|
2014-08-29 09:17:57 -04:00
|
|
|
|
2014-08-29 06:14:43 -04:00
|
|
|
return 0;
|
|
|
|
}
|