1 /* 2 * Copyright (C) 2009 - 2011 Vivien Malerba <malerba@gnome-db.org> 3 * Copyright (C) 2011 Murray Cumming <murrayc@murrayc.com> lit_of_outer_doc_comment(tokens: &TokenStream) -> Literal4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 */ 19 20 #include <libgda/libgda.h> 21 22 int 23 main (int argc, char** argv) 24 { 25 gchar *file; 26 GdaBinary bin; 27 gchar *bin_data; 28 gsize bin_length; 29 GError *error = NULL; 30 31 /* load binary data */ 32 file = g_build_filename (CHECK_FILES, "data", "sales_test.db", NULL); 33 if (! g_file_get_contents (file, &bin_data, &bin_length, &error)) { 34 g_print ("Error reading binary file: %s\n", error->message); 35 return EXIT_FAILURE; 36 } 37 g_free (file); 38 bin.data = (guchar*) bin_data; 39 bin.binary_length = bin_length; 40 41 /* convert to string */ 42 gchar *conv1; 43 conv1 = gda_binary_to_string (&bin, 0); 44 45 /* convert back to binary */ 46 GdaBinary *bin2; 47 bin2 = gda_string_to_binary (conv1); 48 49 /* compare bin */ 50 if (bin.binary_length != bin2->binary_length) { 51 g_print ("Error: binary length differ: from %ld to %ld\n", 52 bin.binary_length, bin2->binary_length); 53 return EXIT_FAILURE; 54 } 55 gint i; 56 for (i = 0; i < bin.binary_length; i++) { 57 if (bin.data[i] != bin2->data[i]) { 58 g_print ("Error: binary differ orig[%d]=%d and copy[%d]=%d\n", 59 i, bin.data[i], i, bin2->data[i]); 60 return EXIT_FAILURE; 61 } 62 } 63 64 g_free (conv1); 65 gda_binary_free (bin2); 66 g_free (bin_data); 67 68 g_print ("Ok (file size: %d)\n", bin_length); 69 return EXIT_SUCCESS; 70 } 71