summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@gmail.com>2012-12-11 22:18:16 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2013-01-09 13:56:06 +0100
commitf0b2662c42d6c0d4ed27eed1d4d5eb86cc5ffb29 (patch)
tree5caba3aca55578fa19e5c84533c16ccb380c6caf
parent5fe3c5109cf2ecd77dd40173f491722689d5af27 (diff)
downloadmsitools-f0b2662c42d6c0d4ed27eed1d4d5eb86cc5ffb29.tar.gz
msitools-f0b2662c42d6c0d4ed27eed1d4d5eb86cc5ffb29.tar.xz
msitools-f0b2662c42d6c0d4ed27eed1d4d5eb86cc5ffb29.zip
record: make API more GObject like
Use TRUE for success. GErrors doesn't seem useful for LibmsiRecord.
-rw-r--r--include/libmsi-record.h33
-rw-r--r--libmsi/libmsi-query.c4
-rw-r--r--libmsi/libmsi-record.c80
-rw-r--r--libmsi/table.c23
-rw-r--r--tests/test.h2
-rw-r--r--tests/testdatabase.c40
-rw-r--r--tests/testrecord.c106
-rw-r--r--tools/msibuild.c3
-rw-r--r--tools/msiinfo.c16
9 files changed, 150 insertions, 157 deletions
diff --git a/include/libmsi-record.h b/include/libmsi-record.h
index 13a766e..986e76e 100644
--- a/include/libmsi-record.h
+++ b/include/libmsi-record.h
@@ -41,17 +41,28 @@ struct _LibmsiRecordClass
GType libmsi_record_get_type (void) G_GNUC_CONST;
-LibmsiRecord * libmsi_record_new (guint count);
-LibmsiResult libmsi_record_clear (LibmsiRecord *);
-LibmsiResult libmsi_record_set_int (LibmsiRecord *,unsigned,int);
-LibmsiResult libmsi_record_set_string (LibmsiRecord *,unsigned,const char *);
-gchar * libmsi_record_get_string (const LibmsiRecord *,unsigned);
-unsigned libmsi_record_get_field_count (const LibmsiRecord *);
-int libmsi_record_get_int (const LibmsiRecord *,unsigned);
-gboolean libmsi_record_is_null (const LibmsiRecord *,unsigned);
-
-LibmsiResult libmsi_record_load_stream (LibmsiRecord *,unsigned,const char *);
-LibmsiResult libmsi_record_save_stream (LibmsiRecord *,unsigned,char*,unsigned *);
+LibmsiRecord * libmsi_record_new (guint count);
+gboolean libmsi_record_clear (LibmsiRecord *record);
+guint libmsi_record_get_field_count (const LibmsiRecord *record);
+gboolean libmsi_record_is_null (const LibmsiRecord *record,
+ guint field);
+gboolean libmsi_record_set_int (LibmsiRecord *record,
+ guint field,
+ gint val);
+gint libmsi_record_get_int (const LibmsiRecord *record,
+ guint field);
+gboolean libmsi_record_set_string (LibmsiRecord *record,
+ guint field,
+ const gchar *val);
+gchar * libmsi_record_get_string (const LibmsiRecord *record,
+ guint field);
+gboolean libmsi_record_load_stream (LibmsiRecord *record,
+ guint field,
+ const gchar *filename);
+gboolean libmsi_record_save_stream (LibmsiRecord *rec,
+ guint field,
+ gchar *buf,
+ guint *sz);
G_END_DECLS
diff --git a/libmsi/libmsi-query.c b/libmsi/libmsi-query.c
index ecb3f14..88e598f 100644
--- a/libmsi/libmsi-query.c
+++ b/libmsi/libmsi-query.c
@@ -471,7 +471,7 @@ LibmsiResult libmsi_query_execute(LibmsiQuery *query, LibmsiRecord *rec)
return ret;
}
-static unsigned msi_set_record_type_string( LibmsiRecord *rec, unsigned field,
+static void msi_set_record_type_string( LibmsiRecord *rec, unsigned field,
unsigned type, bool temporary )
{
static const char fmt[] = "%d";
@@ -505,7 +505,7 @@ static unsigned msi_set_record_type_string( LibmsiRecord *rec, unsigned field,
TRACE("type %04x -> %s\n", type, debugstr_a(szType) );
- return libmsi_record_set_string( rec, field, szType );
+ libmsi_record_set_string( rec, field, szType );
}
unsigned _libmsi_query_get_column_info( LibmsiQuery *query, LibmsiColInfo info, LibmsiRecord **prec )
diff --git a/libmsi/libmsi-record.c b/libmsi/libmsi-record.c
index b472318..cc5c2aa 100644
--- a/libmsi/libmsi-record.c
+++ b/libmsi/libmsi-record.c
@@ -71,13 +71,13 @@ _libmsi_free_field (LibmsiField *field )
static void
libmsi_record_finalize (GObject *object)
{
- LibmsiRecord *p = LIBMSI_RECORD (object);
+ LibmsiRecord *self = LIBMSI_RECORD (object);
unsigned i;
- for (i = 0; i <= p->count; i++ )
- _libmsi_free_field (&p->fields[i]);
+ for (i = 0; i <= self->count; i++ )
+ _libmsi_free_field (&self->fields[i]);
- g_free (p->fields);
+ g_free (self->fields);
G_OBJECT_CLASS (libmsi_record_parent_class)->finalize (object);
}
@@ -86,11 +86,11 @@ static void
libmsi_record_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
g_return_if_fail (LIBMSI_IS_RECORD (object));
- LibmsiRecord *p = LIBMSI_RECORD (object);
+ LibmsiRecord *self = LIBMSI_RECORD (object);
switch (prop_id) {
case PROP_COUNT:
- p->count = g_value_get_uint (value);
+ self->count = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -102,11 +102,11 @@ static void
libmsi_record_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
g_return_if_fail (LIBMSI_IS_RECORD (object));
- LibmsiRecord *p = LIBMSI_RECORD (object);
+ LibmsiRecord *self = LIBMSI_RECORD (object);
switch (prop_id) {
case PROP_COUNT:
- g_value_set_uint (value, p->count);
+ g_value_set_uint (value, self->count);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -118,10 +118,9 @@ static void
libmsi_record_constructed (GObject *object)
{
LibmsiRecord *self = LIBMSI_RECORD (object);
- LibmsiRecord *p = self;
// FIXME: +1 could be removed if accessing with idx-1
- p->fields = g_new0 (LibmsiField, p->count + 1);
+ self->fields = g_new0 (LibmsiField, self->count + 1);
G_OBJECT_CLASS (libmsi_record_parent_class)->constructed (object);
}
@@ -142,12 +141,12 @@ libmsi_record_class_init (LibmsiRecordClass *klass)
G_PARAM_STATIC_STRINGS));
}
-unsigned libmsi_record_get_field_count( const LibmsiRecord *rec )
+guint
+libmsi_record_get_field_count (const LibmsiRecord *self)
{
- if( !rec )
- return -1;
+ g_return_val_if_fail (LIBMSI_IS_RECORD (self), 0);
- return rec->count;
+ return self->count;
}
static bool expr_int_from_string( const char *str, int *out )
@@ -216,11 +215,12 @@ unsigned _libmsi_record_copy_field( LibmsiRecord *in_rec, unsigned in_n,
return r;
}
-int libmsi_record_get_int( const LibmsiRecord *rec, unsigned field)
+gint
+libmsi_record_get_int (const LibmsiRecord *rec, guint field)
{
int ret = 0;
- TRACE("%p %d\n", rec, field);
+ g_return_val_if_fail (LIBMSI_IS_RECORD (rec), LIBMSI_NULL_INT);
if( !rec )
return LIBMSI_NULL_INT;
@@ -243,14 +243,13 @@ int libmsi_record_get_int( const LibmsiRecord *rec, unsigned field)
return LIBMSI_NULL_INT;
}
-LibmsiResult libmsi_record_clear( LibmsiRecord *rec )
+gboolean libmsi_record_clear( LibmsiRecord *rec )
{
unsigned i;
- TRACE("%d\n", rec );
+ g_return_val_if_fail (LIBMSI_IS_RECORD (rec), FALSE);
- if( !rec )
- return LIBMSI_RESULT_INVALID_HANDLE;
+ TRACE("%p\n", rec );
g_object_ref(rec);
for( i=0; i<=rec->count; i++)
@@ -261,24 +260,23 @@ LibmsiResult libmsi_record_clear( LibmsiRecord *rec )
}
g_object_unref(rec);
- return LIBMSI_RESULT_SUCCESS;
+ return TRUE;
}
-LibmsiResult libmsi_record_set_int( LibmsiRecord *rec, unsigned field, int iVal )
+gboolean libmsi_record_set_int( LibmsiRecord *rec, unsigned field, int iVal )
{
TRACE("%p %u %d\n", rec, field, iVal);
- if( !rec )
- return LIBMSI_RESULT_INVALID_HANDLE;
+ g_return_val_if_fail (LIBMSI_IS_RECORD (rec), FALSE);
if( field > rec->count )
- return LIBMSI_RESULT_INVALID_PARAMETER;
+ return FALSE;
_libmsi_free_field( &rec->fields[field] );
rec->fields[field].type = LIBMSI_FIELD_TYPE_INT;
rec->fields[field].u.iVal = iVal;
- return LIBMSI_RESULT_SUCCESS;
+ return TRUE;
}
gboolean libmsi_record_is_null( const LibmsiRecord *rec, unsigned field )
@@ -287,8 +285,7 @@ gboolean libmsi_record_is_null( const LibmsiRecord *rec, unsigned field )
TRACE("%p %d\n", rec, field );
- if( !rec )
- return 0;
+ g_return_val_if_fail (LIBMSI_IS_RECORD (rec), TRUE);
r = ( field > rec->count ) ||
( rec->fields[field].type == LIBMSI_FIELD_TYPE_NULL );
@@ -375,17 +372,16 @@ unsigned _libmsi_record_get_string(const LibmsiRecord *rec, unsigned field,
return ret;
}
-LibmsiResult libmsi_record_set_string( LibmsiRecord *rec, unsigned field, const char *szValue )
+gboolean libmsi_record_set_string( LibmsiRecord *rec, unsigned field, const char *szValue )
{
char *str;
- TRACE("%d %d %s\n", rec, field, debugstr_a(szValue));
+ TRACE("%p %d %s\n", rec, field, debugstr_a(szValue));
- if( !rec )
- return LIBMSI_RESULT_INVALID_HANDLE;
+ g_return_val_if_fail (LIBMSI_IS_RECORD (rec), FALSE);
if( field > rec->count )
- return LIBMSI_RESULT_INVALID_FIELD;
+ return FALSE;
_libmsi_free_field( &rec->fields[field] );
@@ -401,7 +397,7 @@ LibmsiResult libmsi_record_set_string( LibmsiRecord *rec, unsigned field, const
rec->fields[field].u.szVal = NULL;
}
- return 0;
+ return TRUE;
}
/* read the data in a file into a memory-backed GsfInput */
@@ -490,20 +486,19 @@ unsigned _libmsi_record_load_stream_from_file(LibmsiRecord *rec, unsigned field,
return LIBMSI_RESULT_SUCCESS;
}
-LibmsiResult libmsi_record_load_stream(LibmsiRecord *rec, unsigned field, const char *szFilename)
+gboolean libmsi_record_load_stream(LibmsiRecord *rec, unsigned field, const char *szFilename)
{
unsigned ret;
- TRACE("%d %d %s\n", rec, field, debugstr_a(szFilename));
+ TRACE("%p %d %s\n", rec, field, debugstr_a(szFilename));
- if( !rec )
- return LIBMSI_RESULT_INVALID_HANDLE;
+ g_return_val_if_fail (LIBMSI_IS_RECORD (rec), FALSE);
g_object_ref(rec);
ret = _libmsi_record_load_stream_from_file( rec, field, szFilename );
g_object_unref(rec);
- return ret;
+ return ret == LIBMSI_RESULT_SUCCESS;
}
unsigned _libmsi_record_save_stream(const LibmsiRecord *rec, unsigned field, char *buf, unsigned *sz)
@@ -555,20 +550,19 @@ unsigned _libmsi_record_save_stream(const LibmsiRecord *rec, unsigned field, cha
return LIBMSI_RESULT_SUCCESS;
}
-LibmsiResult libmsi_record_save_stream(LibmsiRecord *rec, unsigned field, char *buf, unsigned *sz)
+gboolean libmsi_record_save_stream(LibmsiRecord *rec, unsigned field, char *buf, unsigned *sz)
{
unsigned ret;
TRACE("%d %d %p %p\n", rec, field, buf, sz);
- if( !rec )
- return LIBMSI_RESULT_INVALID_HANDLE;
+ g_return_val_if_fail (LIBMSI_IS_RECORD (rec), FALSE);
g_object_ref(rec);
ret = _libmsi_record_save_stream( rec, field, buf, sz );
g_object_unref(rec);
- return ret;
+ return ret == LIBMSI_RESULT_SUCCESS;
}
unsigned _libmsi_record_set_gsf_input( LibmsiRecord *rec, unsigned field, GsfInput *stm )
diff --git a/libmsi/table.c b/libmsi/table.c
index c7a7e36..713ec9b 100644
--- a/libmsi/table.c
+++ b/libmsi/table.c
@@ -788,7 +788,7 @@ unsigned msi_create_table( LibmsiDatabase *db, const char *name, column_info *co
goto err;
r = libmsi_record_set_string( rec, 1, name );
- if( r )
+ if (!r)
goto err;
r = tv->ops->insert_row( tv, rec, -1, persistent == LIBMSI_CONDITION_FALSE );
@@ -818,8 +818,7 @@ unsigned msi_create_table( LibmsiDatabase *db, const char *name, column_info *co
if( !rec )
goto err;
- r = libmsi_record_set_string( rec, 1, name );
- if( r )
+ if (!libmsi_record_set_string( rec, 1, name ))
goto err;
/*
@@ -829,16 +828,9 @@ unsigned msi_create_table( LibmsiDatabase *db, const char *name, column_info *co
nField = 1;
for( col = col_info; col; col = col->next )
{
- r = libmsi_record_set_int( rec, 2, nField );
- if( r )
- goto err;
-
- r = libmsi_record_set_string( rec, 3, col->column );
- if( r )
- goto err;
-
- r = libmsi_record_set_int( rec, 4, col->type );
- if( r )
+ if (!libmsi_record_set_int (rec, 2, nField) ||
+ !libmsi_record_set_string (rec, 3, col->column) ||
+ !libmsi_record_set_int(rec, 4, col->type))
goto err;
r = tv->ops->insert_row( tv, rec, -1, false );
@@ -1237,9 +1229,8 @@ static unsigned _libmsi_add_stream( LibmsiDatabase *db, const char *name, GsfInp
if ( !rec )
return LIBMSI_RESULT_OUTOFMEMORY;
- r = libmsi_record_set_string( rec, 1, name );
- if ( r != LIBMSI_RESULT_SUCCESS )
- goto err;
+ if (!libmsi_record_set_string(rec, 1, name))
+ goto err;
r = _libmsi_record_set_gsf_input( rec, 2, data );
if ( r != LIBMSI_RESULT_SUCCESS )
diff --git a/tests/test.h b/tests/test.h
index 51aeeed..05f3623 100644
--- a/tests/test.h
+++ b/tests/test.h
@@ -28,7 +28,7 @@ static inline void check_record_string(LibmsiRecord *rec, unsigned field, const
if (val == NULL) {
ok (!str, "Should return null\n");
} else {
- ok (str, "expected string", str);
+ ok (str, "expected string\n", str);
if (str)
ok (g_str_equal (str, val), "got %s != %s expected\n", str, val);
}
diff --git a/tests/testdatabase.c b/tests/testdatabase.c
index 8b8482b..87f457d 100644
--- a/tests/testdatabase.c
+++ b/tests/testdatabase.c
@@ -388,11 +388,11 @@ static void test_msiinsert(void)
/* construct a record to insert */
hrec = libmsi_record_new(4);
r = libmsi_record_set_int(hrec, 1, 2);
- ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_record_set_int failed\n");
+ ok(r, "libmsi_record_set_int failed\n");
r = libmsi_record_set_string(hrec, 2, "Adam");
- ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_record_set_string failed\n");
+ ok(r, "libmsi_record_set_string failed\n");
r = libmsi_record_set_string(hrec, 3, "96905305");
- ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_record_set_string failed\n");
+ ok(r, "libmsi_record_set_string failed\n");
/* insert another value, using a record and wildcards */
sql = "INSERT INTO `phone` ( `id`, `name`, `number` )"
@@ -1174,7 +1174,7 @@ static void test_streamtable(void)
libmsi_record_set_string( rec, 1, "data" );
r = libmsi_record_load_stream( rec, 2, "test.txt" );
- ok( r == LIBMSI_RESULT_SUCCESS, "Failed to add stream data to the record: %d\n", r);
+ ok(r, "Failed to add stream data to the record: %d\n", r);
unlink("test.txt");
@@ -1197,7 +1197,7 @@ static void test_streamtable(void)
libmsi_record_set_string( rec, 1, "data1" );
r = libmsi_record_load_stream( rec, 2, "test1.txt" );
- ok( r == LIBMSI_RESULT_SUCCESS, "Failed to add stream data to the record: %d\n", r);
+ ok(r, "Failed to add stream data to the record: %d\n", r);
unlink("test1.txt");
@@ -1229,7 +1229,7 @@ static void test_streamtable(void)
size = sizeof(buf);
memset(buf, 0, sizeof(buf));
r = libmsi_record_save_stream( rec, 2, buf, &size );
- ok( r == LIBMSI_RESULT_SUCCESS, "Failed to get stream: %d\n", r);
+ ok(r, "Failed to get stream: %d\n", r);
ok( g_str_equal(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf);
g_object_unref( rec );
@@ -1252,7 +1252,7 @@ static void test_streamtable(void)
size = sizeof(buf);
memset(buf, 0, sizeof(buf));
r = libmsi_record_save_stream( rec, 2, buf, &size );
- ok( r == LIBMSI_RESULT_SUCCESS, "Failed to get stream: %d\n", r);
+ ok( r, "Failed to get stream: %d\n", r);
ok( g_str_equal(buf, "test1.txt\n"), "Expected 'test1.txt\\n', got %s\n", buf);
g_object_unref( rec );
@@ -1264,7 +1264,7 @@ static void test_streamtable(void)
rec = libmsi_record_new( 1 );
r = libmsi_record_load_stream( rec, 1, "test2.txt" );
- ok( r == LIBMSI_RESULT_SUCCESS, "Failed to add stream data to the record: %d\n", r);
+ ok(r, "Failed to add stream data to the record: %d\n", r);
unlink("test2.txt");
@@ -1296,7 +1296,7 @@ static void test_streamtable(void)
size = sizeof(buf);
memset(buf, 0, sizeof(buf));
r = libmsi_record_save_stream( rec, 2, buf, &size );
- ok( r == LIBMSI_RESULT_SUCCESS, "Failed to get stream: %d\n", r);
+ ok(r, "Failed to get stream: %d\n", r);
todo_wine ok( g_str_equal(buf, "test2.txt\n"), "Expected 'test2.txt\\n', got %s\n", buf);
g_object_unref( rec );
@@ -1344,7 +1344,7 @@ static void test_binary(void)
create_file( "test.txt" );
rec = libmsi_record_new( 1 );
r = libmsi_record_load_stream( rec, 1, "test.txt" );
- ok( r == LIBMSI_RESULT_SUCCESS, "Failed to add stream data to the record: %d\n", r);
+ ok(r, "Failed to add stream data to the record: %d\n", r);
unlink( "test.txt" );
sql = "INSERT INTO `Binary` ( `Name`, `ID`, `Data` ) VALUES ( 'filename1', 1, ? )";
@@ -1371,7 +1371,7 @@ static void test_binary(void)
size = sizeof(buf);
memset( buf, 0, sizeof(buf) );
r = libmsi_record_save_stream( rec, 2, buf, &size );
- ok( r == LIBMSI_RESULT_SUCCESS, "Failed to get stream: %d\n", r );
+ ok(r, "Failed to get stream: %d\n", r );
ok( g_str_equal(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf );
g_object_unref( rec );
@@ -1386,7 +1386,7 @@ static void test_binary(void)
size = sizeof(buf);
memset( buf, 0, sizeof(buf) );
r = libmsi_record_save_stream( rec, 3, buf, &size );
- ok( r == LIBMSI_RESULT_SUCCESS, "Failed to get stream: %d\n", r );
+ ok(r, "Failed to get stream: %d\n", r );
ok( g_str_equal(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf );
g_object_unref( rec );
@@ -2047,7 +2047,7 @@ static void test_binary_import(void)
size = sizeof(buf);
memset(buf, 0, size);
r = libmsi_record_save_stream(rec, 2, buf, &size);
- ok(r == LIBMSI_RESULT_SUCCESS, "Failed to get stream: %d\n", r);
+ ok(r, "Failed to get stream: %d\n", r);
ok(g_str_equal(buf, "just some words"),
"Expected 'just some words', got %s\n", buf);
@@ -2514,11 +2514,11 @@ static void test_try_transform(void)
hrec = libmsi_record_new(2);
r = libmsi_record_set_int(hrec, 1, 2);
- ok(r == LIBMSI_RESULT_SUCCESS, "failed to set integer\n");
+ ok(r, "failed to set integer\n");
write_file("testdata.bin", "lamyon", 6);
r = libmsi_record_load_stream(hrec, 2, "testdata.bin");
- ok(r == LIBMSI_RESULT_SUCCESS, "failed to set stream\n");
+ ok(r, "failed to set stream\n");
sql = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
r = run_query(hdb, hrec, sql);
@@ -2585,7 +2585,7 @@ static void test_try_transform(void)
/* check the contents of the stream */
sz = sizeof buffer;
r = libmsi_record_save_stream( hrec, 1, buffer, &sz );
- ok(r == LIBMSI_RESULT_SUCCESS, "read stream failed\n");
+ ok(r, "read stream failed\n");
ok(!memcmp(buffer, "naengmyon", 9), "stream data was wrong\n");
ok(sz == 9, "stream data was wrong size\n");
if (hrec) g_object_unref(hrec);
@@ -3707,7 +3707,7 @@ static void test_integers(void)
ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
r = libmsi_record_get_field_count(rec);
- ok(r == -1, "record count wrong: %d\n", r);
+ ok(r == 0, "record count wrong: %d\n", r);
ok(rec == NULL, "Must be null");
/* insert legitimate values into it */
@@ -5814,7 +5814,7 @@ static void test_storages_table(void)
libmsi_record_set_string(hrec, 1, "stgname");
r = libmsi_record_load_stream(hrec, 2, "storage.bin");
- ok(r == LIBMSI_RESULT_SUCCESS, "Failed to add stream data to the hrecord: %d\n", r);
+ ok(r, "Failed to add stream data to the hrecord: %d\n", r);
unlink("storage.bin");
@@ -5844,7 +5844,7 @@ static void test_storages_table(void)
size = sizeof(buf);
strcpy(buf, "apple");
r = libmsi_record_save_stream(hrec, 2, buf, &size);
- ok(r == LIBMSI_RESULT_INVALID_DATA, "Expected ERROR_INVALID_DATA, got %d\n", r);
+ ok(!r, "Expected ERROR_INVALID_DATA, got %d\n", r);
ok(g_str_equal(buf, "apple"), "Expected buf to be unchanged, got %s\n", buf);
ok(size == 0, "Expected 0, got %d\n", size);
@@ -6598,7 +6598,7 @@ static void test_dbmerge(void)
size = sizeof(buf);
memset(buf, 0, sizeof(buf));
r = libmsi_record_save_stream(hrec, 2, buf, &size);
- ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
+ ok(r, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
ok(g_str_equal(buf, "binary.dat\n"),
"Expected \"binary.dat\\n\", got \"%s\"\n", buf);
diff --git a/tests/testrecord.c b/tests/testrecord.c
index 5736c9c..67061c0 100644
--- a/tests/testrecord.c
+++ b/tests/testrecord.c
@@ -59,17 +59,17 @@ static void test_msirecord (void)
/* check behaviour with an invalid record */
r = libmsi_record_get_field_count (0);
- ok (r == -1, "field count for invalid record not -1\n");
+ ok (r == 0, "field count for invalid record not -1\n");
r = libmsi_record_is_null (0, 0);
- ok (r == 0, "invalid handle not considered to be non-null...\n");
+ ok (r == true, "invalid handle not considered to be null...\n");
r = libmsi_record_get_int (0, 0);
ok (r == LIBMSI_NULL_INT, "got integer from invalid record\n");
r = libmsi_record_set_int (0, 0, 0);
- ok (r == LIBMSI_RESULT_INVALID_HANDLE, "libmsi_record_set_int returned wrong error\n");
+ ok (!r, "libmsi_record_set_int returned wrong error\n");
r = libmsi_record_set_int (0, -1, 0);
- ok (r == LIBMSI_RESULT_INVALID_HANDLE, "libmsi_record_set_int returned wrong error\n");
+ ok (!r, "libmsi_record_set_int returned wrong error\n");
r = libmsi_record_clear (0);
- ok (r == LIBMSI_RESULT_INVALID_HANDLE, "libmsi_record_clear returned wrong error\n");
+ ok (!r, "libmsi_record_clear returned wrong error\n");
/* check behaviour of a record with 0 elements */
@@ -86,115 +86,115 @@ static void test_msirecord (void)
check_record_string (h, 0, "");
/* same record, but add an integer to it */
r = libmsi_record_set_int (h, 0, 0);
- ok (r == LIBMSI_RESULT_SUCCESS, "Failed to set integer at 0 to 0\n");
+ ok (r, "Failed to set integer at 0 to 0\n");
r = libmsi_record_is_null (h, 0);
- ok (r == 0, "new record is null after setting an integer\n");
+ ok (r == false, "new record is null after setting an integer\n");
r = libmsi_record_set_int (h, 0, 1);
- ok (r == LIBMSI_RESULT_SUCCESS, "Failed to set integer at 0 to 1\n");
+ ok (r, "Failed to set integer at 0 to 1\n");
r = libmsi_record_set_int (h, 1, 1);
- ok (r == LIBMSI_RESULT_INVALID_PARAMETER, "set integer at 1\n");
+ ok (!r, "set integer at 1\n");
r = libmsi_record_set_int (h, -1, 0);
- ok (r == LIBMSI_RESULT_INVALID_PARAMETER, "set integer at -1\n");
+ ok (!r, "set integer at -1\n");
r = libmsi_record_is_null (h, 0);
- ok (r == 0, "new record is null after setting an integer\n");
+ ok (r == false, "new record is null after setting an integer\n");
r = libmsi_record_get_int (h, 0);
- ok (r == 1, "failed to get integer\n");
+ ok (r, "failed to get integer\n");
/* same record, but add a null or empty string to it */
r = libmsi_record_set_string (h, 0, NULL);
- ok (r == LIBMSI_RESULT_SUCCESS, "Failed to set null string at 0\n");
+ ok (r, "Failed to set null string at 0\n");
r = libmsi_record_is_null (h, 0);
ok (r == true, "null string not null field\n");
check_record_string (h, 0, "");
r = libmsi_record_set_string (h, 0, "");
- ok (r == LIBMSI_RESULT_SUCCESS, "Failed to set empty string at 0\n");
+ ok (r, "Failed to set empty string at 0\n");
r = libmsi_record_is_null (h, 0);
ok (r == true, "null string not null field\n");
check_record_string (h, 0, "");
/* same record, but add a string to it */
r = libmsi_record_set_string (h, 0, str);
- ok (r == LIBMSI_RESULT_SUCCESS, "Failed to set string at 0\n");
+ ok (r, "Failed to set string at 0\n");
r = libmsi_record_get_int (h, 0);
ok (r == LIBMSI_NULL_INT, "should get invalid integer\n");
check_record_string (h, 0, str);
/* same record, check we can wipe all the data */
r = libmsi_record_clear (h);
- ok (r == LIBMSI_RESULT_SUCCESS, "Failed to clear record\n");
+ ok (r, "Failed to clear record\n");
r = libmsi_record_clear (h);
- ok (r == LIBMSI_RESULT_SUCCESS, "Failed to clear record again\n");
+ ok (r, "Failed to clear record again\n");
r = libmsi_record_is_null (h, 0);
ok (r, "cleared record wasn't null\n");
/* same record, try converting strings to integers */
i = libmsi_record_set_string (h, 0, "42");
- ok (i == LIBMSI_RESULT_SUCCESS, "Failed to set string at 0\n");
+ ok (i, "Failed to set string at 0\n");
i = libmsi_record_get_int (h, 0);
ok (i == 42, "should get invalid integer\n");
i = libmsi_record_set_string (h, 0, "-42");
- ok (i == LIBMSI_RESULT_SUCCESS, "Failed to set string at 0\n");
+ ok (i, "Failed to set string at 0\n");
i = libmsi_record_get_int (h, 0);
ok (i == -42, "should get invalid integer\n");
i = libmsi_record_set_string (h, 0, " 42");
- ok (i == LIBMSI_RESULT_SUCCESS, "Failed to set string at 0\n");
+ ok (i, "Failed to set string at 0\n");
i = libmsi_record_get_int (h, 0);
ok (i == LIBMSI_NULL_INT, "should get invalid integer\n");
i = libmsi_record_set_string (h, 0, "42 ");
- ok (i == LIBMSI_RESULT_SUCCESS, "Failed to set string at 0\n");
+ ok (i, "Failed to set string at 0\n");
i = libmsi_record_get_int (h, 0);
ok (i == LIBMSI_NULL_INT, "should get invalid integer\n");
i = libmsi_record_set_string (h, 0, "42.0");
- ok (i == LIBMSI_RESULT_SUCCESS, "Failed to set string at 0\n");
+ ok (i, "Failed to set string at 0\n");
i = libmsi_record_get_int (h, 0);
ok (i == LIBMSI_NULL_INT, "should get invalid integer\n");
i = libmsi_record_set_string (h, 0, "0x42");
- ok (i == LIBMSI_RESULT_SUCCESS, "Failed to set string at 0\n");
+ ok (i, "Failed to set string at 0\n");
i = libmsi_record_get_int (h, 0);
ok (i == LIBMSI_NULL_INT, "should get invalid integer\n");
i = libmsi_record_set_string (h, 0, "1000000000000000");
- ok (i == LIBMSI_RESULT_SUCCESS, "Failed to set string at 0\n");
+ ok (i, "Failed to set string at 0\n");
i = libmsi_record_get_int (h, 0);
ok (i == -1530494976, "should get truncated integer\n");
i = libmsi_record_set_string (h, 0, "2147483647");
- ok (i == LIBMSI_RESULT_SUCCESS, "Failed to set string at 0\n");
+ ok (i, "Failed to set string at 0\n");
i = libmsi_record_get_int (h, 0);
ok (i == 2147483647, "should get maxint\n");
i = libmsi_record_set_string (h, 0, "-2147483647");
- ok (i == LIBMSI_RESULT_SUCCESS, "Failed to set string at 0\n");
+ ok (i, "Failed to set string at 0\n");
i = libmsi_record_get_int (h, 0);
ok (i == -2147483647, "should get -maxint-1\n");
i = libmsi_record_set_string (h, 0, "4294967297");
- ok (i == LIBMSI_RESULT_SUCCESS, "Failed to set string at 0\n");
+ ok (i, "Failed to set string at 0\n");
i = libmsi_record_get_int (h, 0);
ok (i == 1, "should get one\n");
i = libmsi_record_set_string (h, 0, "foo");
- ok (i == LIBMSI_RESULT_SUCCESS, "Failed to set string at 0\n");
+ ok (i, "Failed to set string at 0\n");
i = libmsi_record_get_int (h, 0);
ok (i == LIBMSI_NULL_INT, "should get zero\n");
i = libmsi_record_set_string (h, 0, "");
- ok (i == LIBMSI_RESULT_SUCCESS, "Failed to set string at 0\n");
+ ok (i, "Failed to set string at 0\n");
i = libmsi_record_get_int (h, 0);
ok (i == LIBMSI_NULL_INT, "should get zero\n");
i = libmsi_record_set_string (h, 0, "+1");
- ok (i == LIBMSI_RESULT_SUCCESS, "Failed to set string at 0\n");
+ ok (i, "Failed to set string at 0\n");
i = libmsi_record_get_int (h, 0);
ok (i == LIBMSI_NULL_INT, "should get zero\n");
/* same record, try converting integers to strings */
r = libmsi_record_set_int (h, 0, 32);
- ok (r == LIBMSI_RESULT_SUCCESS, "Failed to set integer at 0 to 32\n");
+ ok (r, "Failed to set integer at 0 to 32\n");
check_record_string (h, 0, "32");
r = libmsi_record_set_int (h, 0, -32);
- ok (r == LIBMSI_RESULT_SUCCESS, "Failed to set integer at 0 to 32\n");
+ ok (r, "Failed to set integer at 0 to 32\n");
check_record_string (h, 0, "-32");
/* same record, now try streams */
r = libmsi_record_load_stream (h, 0, NULL);
- ok (r == LIBMSI_RESULT_INVALID_PARAMETER, "set NULL stream\n");
+ ok (!r, "set NULL stream\n");
sz = sizeof buf;
r = libmsi_record_save_stream (h, 0, buf, &sz);
- ok (r == LIBMSI_RESULT_INVALID_DATATYPE, "read non-stream type\n");
+ ok (!r, "read non-stream type\n");
ok (sz == sizeof buf, "set sz\n");
/* same record, now close it */
@@ -207,49 +207,49 @@ static void test_msirecord (void)
h = libmsi_record_new (2);
ok (h, "couldn't create a two field record\n");
r = libmsi_record_load_stream (h, 0, filename);
- ok (r == LIBMSI_RESULT_INVALID_PARAMETER, "added stream to field 0\n");
+ ok (!r, "added stream to field 0\n");
r = libmsi_record_load_stream (h, 1, filename);
- ok (r == LIBMSI_RESULT_SUCCESS, "failed to add stream to record\n");
+ ok (r, "failed to add stream to record\n");
r = libmsi_record_save_stream (h, 1, buf, NULL);
- ok (r == LIBMSI_RESULT_INVALID_PARAMETER, "should return error\n");
+ ok (!r, "should return error\n");
unlink (filename); /* Windows 98 doesn't like this at all, so don't check return. */
r = libmsi_record_save_stream (h, 1, NULL, NULL);
- ok (r == LIBMSI_RESULT_INVALID_PARAMETER, "should return error\n");
+ ok (!r, "should return error\n");
sz = sizeof buf;
r = libmsi_record_save_stream (h, 1, NULL, &sz);
- ok (r == LIBMSI_RESULT_SUCCESS, "failed to read stream\n");
+ ok (r, "failed to read stream\n");
ok (sz == 26, "couldn't get size of stream\n");
sz = 0;
r = libmsi_record_save_stream (h, 1, buf, &sz);
- ok (r == LIBMSI_RESULT_SUCCESS, "failed to read stream\n");
+ ok (r, "failed to read stream\n");
ok (sz == 0, "short read\n");
sz = sizeof buf;
r = libmsi_record_save_stream (h, 1, buf, &sz);
- ok (r == LIBMSI_RESULT_SUCCESS, "failed to read stream\n");
+ ok (r, "failed to read stream\n");
ok (sz == sizeof buf, "short read\n");
ok (!strncmp (buf, "abcdefghij", 10), "read the wrong thing\n");
sz = sizeof buf;
r = libmsi_record_save_stream (h, 1, buf, &sz);
- ok (r == LIBMSI_RESULT_SUCCESS, "failed to read stream\n");
+ ok (r, "failed to read stream\n");
ok (sz == sizeof buf, "short read\n");
ok (!strncmp (buf, "klmnopqrst", 10), "read the wrong thing\n");
memset (buf, 0, sizeof buf);
sz = sizeof buf;
r = libmsi_record_save_stream (h, 1, buf, &sz);
- ok (r == LIBMSI_RESULT_SUCCESS, "failed to read stream\n");
+ ok (r, "failed to read stream\n");
ok (sz == 6, "short read\n");
ok (!strcmp (buf, "uvwxyz"), "read the wrong thing\n");
memset (buf, 0, sizeof buf);
sz = sizeof buf;
r = libmsi_record_save_stream (h, 1, buf, &sz);
- ok (r == LIBMSI_RESULT_SUCCESS, "failed to read stream\n");
+ ok (r, "failed to read stream\n");
ok (sz == 0, "size non-zero at end of stream\n");
ok (buf[0] == 0, "read something at end of the stream\n");
r = libmsi_record_load_stream (h, 1, NULL);
- ok (r == LIBMSI_RESULT_SUCCESS, "failed to reset stream\n");
+ ok (r, "failed to reset stream\n");
sz = 0;
r = libmsi_record_save_stream (h, 1, NULL, &sz);
- ok (r == LIBMSI_RESULT_SUCCESS, "bytes left wrong after reset\n");
+ ok (r, "bytes left wrong after reset\n");
ok (sz == 26, "couldn't get size of stream\n");
/* now close the stream record */
@@ -273,11 +273,11 @@ static void test_MsiRecordGetString (void)
ok (rec != 0, "Expected a valid handle\n");
r = libmsi_record_set_int (rec, 1, 5);
- ok (r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
+ ok (r, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
check_record_string (rec, 1, "5");
r = libmsi_record_set_int (rec, 1, -5);
- ok (r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
+ ok (r, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
check_record_string (rec, 1, "-5");
g_object_unref (rec);
@@ -293,19 +293,19 @@ static void test_MsiRecordGetInteger (void)
ok (rec != 0, "Expected a valid handle\n");
r = libmsi_record_set_string (rec, 1, "5");
- ok (r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
+ ok (r, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
val = libmsi_record_get_int (rec, 1);
ok (val == 5, "Expected 5, got %d\n", val);
r = libmsi_record_set_string (rec, 1, "-5");
- ok (r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
+ ok (r, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
val = libmsi_record_get_int (rec, 1);
ok (val == -5, "Expected -5, got %d\n", val);
r = libmsi_record_set_string (rec, 1, "5apple");
- ok (r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
+ ok (r, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
val = libmsi_record_get_int (rec, 1);
ok (val == LIBMSI_NULL_INT, "Expected LIBMSI_NULL_INT, got %d\n", val);
@@ -338,7 +338,7 @@ static void test_fieldzero (void)
ok (r == LIBMSI_NULL_INT, "Expected LIBMSI_NULL_INT, got %d\n", r);
r = libmsi_record_set_int (rec, 1, 42);
- ok (r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
+ ok (r, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
r = libmsi_record_get_int (rec, 0);
ok (r == LIBMSI_NULL_INT, "Expected LIBMSI_NULL_INT, got %d\n", r);
@@ -352,7 +352,7 @@ static void test_fieldzero (void)
ok (r == 42, "Expected 42, got %d\n", r);
r = libmsi_record_set_string (rec, 1, "bologna");
- ok (r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
+ ok (r, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
r = libmsi_record_get_int (rec, 0);
ok (r == LIBMSI_NULL_INT, "Expected LIBMSI_NULL_INT, got %d\n", r);
diff --git a/tools/msibuild.c b/tools/msibuild.c
index 28d55a1..d0bafb2 100644
--- a/tools/msibuild.c
+++ b/tools/msibuild.c
@@ -182,8 +182,7 @@ static int add_stream(const char *stream, const char *file)
rec = libmsi_record_new(2);
libmsi_record_set_string(rec, 1, stream);
- r = libmsi_record_load_stream(rec, 2, file);
- if (r != LIBMSI_RESULT_SUCCESS)
+ if (!libmsi_record_load_stream(rec, 2, file))
fprintf(stderr, "failed to load stream (%u)\n", r);
r = libmsi_database_open_query(db,
diff --git a/tools/msiinfo.c b/tools/msiinfo.c
index fdf963c..576a8d7 100644
--- a/tools/msiinfo.c
+++ b/tools/msiinfo.c
@@ -406,10 +406,8 @@ static int cmd_extract(struct Command *cmd, int argc, char **argv)
print_libmsi_error(r);
}
- r = libmsi_record_save_stream(rec, 1, NULL, &size);
- if (r) {
- print_libmsi_error(r);
- }
+ if (!libmsi_record_save_stream(rec, 1, NULL, &size))
+ exit(1);
bufsize = (size > 1048576 ? 1048576 : size);
buf = g_malloc(bufsize);
@@ -437,9 +435,9 @@ static unsigned export_create_table(const char *table,
LibmsiRecord *types,
LibmsiRecord *keys)
{
- int num_columns = libmsi_record_get_field_count(names);
- int num_keys = libmsi_record_get_field_count(keys);
- int i, len;
+ guint num_columns = libmsi_record_get_field_count(names);
+ guint num_keys = libmsi_record_get_field_count(keys);
+ guint i, len;
unsigned r;
char size[20], extra[30];
gchar *name, *type;
@@ -532,9 +530,9 @@ static unsigned export_insert(const char *table,
LibmsiRecord *types,
LibmsiRecord *vals)
{
- int num_columns = libmsi_record_get_field_count(names);
+ guint num_columns = libmsi_record_get_field_count(names);
gchar *name, *type;
- int i;
+ guint i;
unsigned r;
unsigned sz;
char *s;