1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* unit-test-util.c: Test gck-util.c
4 Copyright (C) 2011 Collabora Ltd.
6 The Gnome Keyring Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The Gnome Keyring Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the Gnome Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 Author: Stef Walter <stefw@collabora.co.uk>
26 #include "egg/egg-decimal.h"
27 #include "egg/egg-testing.h"
39 static TestDecimal decimal_fixtures[] = {
41 { "2048", "\x08\x00", 2 },
42 { "209328042309", "\x30\xBC\xEC\x71\x45", 5 },
43 { "0002048", "\x08\x00", 2 },
44 { "20480000", "\x01\x38\x80\x00", 4 },
45 { "2521368004379664277055118629334750468402260732427135194366161280379"
46 "6661942758264006541602516197962800670706891657576953487072507942596"
47 "6374424122494538738176144081024494339591946626053519298721214406983"
48 "3606711407748948613853344896472022957466922483835202523097287025430"
49 "5078987427716449092979306938082113263545271808186244259338032237756"
50 "9175402872261192563172038927792670653714043622677577357160052045893"
51 "9513984477743817388078699536715866468499111753894230211101792648120"
52 "1128688482121549927434503046858485918719606735307033123916744787670"
53 "4316000505177621722934283063062034258685067324811300901286708201589"
55 "\xC7\xBB\x16\xF4\xB8\x04\x24\x0F\xFC\xC2\xA7\xAF\x8C\x6E\x67\xE1\x16"
56 "\x7F\xEB\xFA\x7F\xAA\x9D\xFD\x7C\xF2\x75\xB8\xA5\x1F\x27\x35\xF2\xD4"
57 "\x9D\x78\xFB\xF6\x5C\xED\x10\xB4\xE4\x32\x58\x2D\xC9\x1E\x86\x54\xF7"
58 "\x89\x7F\x03\x84\x68\x32\x76\xA9\xA7\x97\xC3\xA3\x6F\x7A\x46\x85\x43"
59 "\x5E\x14\x4D\x47\x01\x81\x06\xE5\xC0\x61\xD7\xC8\x7C\x9B\xE1\x9D\x84"
60 "\x87\x75\x77\x80\x0E\xAE\x91\xB1\x05\x12\xDE\x92\xF2\x98\x84\x1F\x43"
61 "\xD4\xC4\x57\x77\x95\xC5\xE6\x82\xEE\xEA\x0A\xB3\xDD\x8C\x44\x45\x9A"
62 "\x12\xAC\xF9\xC2\x22\xA1\x3F\x03\x31\xDD\x84\xF7\x75\x51\xE0\xFA\x24"
63 "\x8E\x6F\xE9\x58\x4C\xA3\x42\x73\xB9\x5E\x2F\x0D\xCC\xDC\x22\x8A\x48"
64 "\x75\x4A\x76\xA2\x9D\x03\xBA\x5F\xC8\x57\xB5\x1F\x5C\x85\x7E\x8C\x0F"
65 "\xF2\x73\xDA\x96\x67\x7C\xC6\x4D\x54\x2C\x45\x63\xD1\xA6\x7F\xF1\xA0"
66 "\x1F\x3F\x9E\xDF\xF3\x7F\x24\x3D\x6E\xB8\xF7\x4C\xC8\xA7\x27\x95\xA1"
67 "\xDA\x8F\x98\x32\x32\x1B\x7D\xB6\x1B\xFC\x8D\x73\x7C\xD1\x48\x99\xD0"
68 "\xAC\x7C\xF1\x5B\x95\xA5\xFE\xD8\x12\x57\x5C\x7A\x6B\xC5\x5C\x7D\x92"
69 "\xB1\x91\x88\x36\x58\x19\x30\x67\x2D\x73\xF3\x5A\xA6\x31\xC4\x5C\x2D"
74 static const gchar *decimal_failures[] = {
81 test_decode_success (gconstpointer data)
83 const TestDecimal *fixture = data;
87 decoded = egg_decimal_decode (fixture->decimal, -1, &n_decoded);
88 egg_assert_cmpmem (fixture->result, fixture->length, ==, decoded, n_decoded);
93 test_decode_failure (gconstpointer data)
95 const gchar *failure = data;
99 decoded = egg_decimal_decode (failure, -1, &n_decoded);
100 g_assert (decoded == NULL);
104 main (int argc, char **argv)
111 g_test_init (&argc, &argv, NULL);
113 for (i = 0; i < G_N_ELEMENTS (decimal_fixtures); i++) {
114 /* Ellipsize long numbers in test names */
115 decimal = g_strndup (decimal_fixtures[i].decimal, 41);
116 if (strlen (decimal) == 41) {
122 name = g_strdup_printf ("/decimal/decode-success/%s%s", decimal, suffix);
123 g_test_add_data_func (name, &decimal_fixtures[i], test_decode_success);
128 for (i = 0; i < G_N_ELEMENTS (decimal_failures); i++) {
129 name = g_strdup_printf ("/decimal/decode-failure/%s", decimal_failures[i]);
130 g_strcanon (name, "abcdefghijklmnopqrstuvwxyz-_/0123456789", '_');
131 g_test_add_data_func (name, decimal_failures[i], test_decode_failure);
135 return g_test_run ();