Annotation of OpenXM_contrib/gmp/tests/mpz/t-import.c, Revision 1.1.1.1
1.1 ohara 1: /* Test mpz_import.
2:
3: Copyright 2002 Free Software Foundation, Inc.
4:
5: This file is part of the GNU MP Library.
6:
7: The GNU MP Library is free software; you can redistribute it and/or modify
8: it under the terms of the GNU Lesser General Public License as published by
9: the Free Software Foundation; either version 2.1 of the License, or (at your
10: option) any later version.
11:
12: The GNU MP Library is distributed in the hope that it will be useful, but
13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15: License for more details.
16:
17: You should have received a copy of the GNU Lesser General Public License
18: along with the GNU MP Library; see the file COPYING.LIB. If not, write to
19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20: MA 02111-1307, USA. */
21:
22: #include <stdio.h>
23: #include <stdlib.h>
24: #include "gmp.h"
25: #include "gmp-impl.h"
26: #include "tests.h"
27:
28:
29: void
30: check_data (void)
31: {
32: static const struct {
33: const char *want;
34: size_t count;
35: int order;
36: size_t size;
37: int endian;
38: int nail;
39: char src[64];
40:
41: } data[] = {
42:
43: { "0", 0,1, 1,1, 0 },
44: { "0", 1,1, 0,1, 0 },
45:
46: { "0x12345678", 4,1, 1,1, 0, { 0x12, 0x34, 0x56, 0x78 } },
47: { "0x12345678", 1,1, 4,1, 0, { 0x12, 0x34, 0x56, 0x78 } },
48: { "0x12345678", 1,-1, 4,1, 0, { 0x12, 0x34, 0x56, 0x78 } },
49:
50: { "0x12345678", 4,-1, 1,-1, 0, { 0x78, 0x56, 0x34, 0x12 } },
51: { "0x12345678", 1,1, 4,-1, 0, { 0x78, 0x56, 0x34, 0x12 } },
52: { "0x12345678", 1,-1, 4,-1, 0, { 0x78, 0x56, 0x34, 0x12 } },
53:
54: { "0", 5,1, 1,1, 7, { 0xFE, 0xFE, 0xFE, 0xFE, 0xFE } },
55: { "0", 5,-1, 1,1, 7, { 0xFE, 0xFE, 0xFE, 0xFE, 0xFE } },
56: { "0x15", 5,1, 1,1, 7, { 0xFF, 0xFE, 0xFF, 0xFE, 0xFF } },
57:
58: { "0", 3,1, 2,1, 1, { 0x80,0x00, 0x80,0x00, 0x80,0x00 } },
59: { "0", 3,1, 2,-1, 1, { 0x00,0x80, 0x00,0x80, 0x00,0x80 } },
60: { "0", 3,1, 2,1, 15, { 0xFF,0xFE, 0xFF,0xFE, 0xFF,0xFE } },
61:
62: { "0x2A", 3,1, 2,1, 14, { 0xFF,0xFE, 0xFF,0xFE, 0xFF,0xFE } },
63: { "0x06", 3,1, 2,1, 14, { 0xFF,0xFC, 0xFF,0xFD, 0xFF,0xFE } },
64: { "0x24", 3,-1, 2,1, 14, { 0xFF,0xFC, 0xFF,0xFD, 0xFF,0xFE } },
65:
66: { "0x123456789ABC", 3,1, 2,1, 0, { 0x12,0x34, 0x56,0x78, 0x9A,0xBC } },
67: { "0x123456789ABC", 3,-1, 2,1, 0, { 0x9A,0xBC, 0x56,0x78, 0x12,0x34 } },
68: { "0x123456789ABC", 3,1, 2,-1, 0, { 0x34,0x12, 0x78,0x56, 0xBC,0x9A } },
69: { "0x123456789ABC", 3,-1, 2,-1, 0, { 0xBC,0x9A, 0x78,0x56, 0x34,0x12 } },
70:
71: { "0x112233445566778899AABBCC", 3,1, 4,1, 0,
72: { 0x11,0x22,0x33,0x44, 0x55,0x66,0x77,0x88, 0x99,0xAA,0xBB,0xCC } },
73: { "0x112233445566778899AABBCC", 3,-1, 4,1, 0,
74: { 0x99,0xAA,0xBB,0xCC, 0x55,0x66,0x77,0x88, 0x11,0x22,0x33,0x44 } },
75: { "0x112233445566778899AABBCC", 3,1, 4,-1, 0,
76: { 0x44,0x33,0x22,0x11, 0x88,0x77,0x66,0x55, 0xCC,0xBB,0xAA,0x99 } },
77: { "0x112233445566778899AABBCC", 3,-1, 4,-1, 0,
78: { 0xCC,0xBB,0xAA,0x99, 0x88,0x77,0x66,0x55, 0x44,0x33,0x22,0x11 } },
79:
80: { "0x100120023003400450056006700780089009A00AB00BC00C", 3,1, 8,1, 0,
81: { 0x10,0x01,0x20,0x02,0x30,0x03,0x40,0x04,
82: 0x50,0x05,0x60,0x06,0x70,0x07,0x80,0x08,
83: 0x90,0x09,0xA0,0x0A,0xB0,0x0B,0xC0,0x0C } },
84: { "0x100120023003400450056006700780089009A00AB00BC00C", 3,-1, 8,1, 0,
85: { 0x90,0x09,0xA0,0x0A,0xB0,0x0B,0xC0,0x0C,
86: 0x50,0x05,0x60,0x06,0x70,0x07,0x80,0x08,
87: 0x10,0x01,0x20,0x02,0x30,0x03,0x40,0x04 } },
88: { "0x100120023003400450056006700780089009A00AB00BC00C", 3,1, 8,-1, 0,
89: { 0x04,0x40,0x03,0x30,0x02,0x20,0x01,0x10,
90: 0x08,0x80,0x07,0x70,0x06,0x60,0x05,0x50,
91: 0x0C,0xC0,0x0B,0xB0,0x0A,0xA0,0x09,0x90 } },
92: { "0x100120023003400450056006700780089009A00AB00BC00C", 3,-1, 8,-1, 0,
93: { 0x0C,0xC0,0x0B,0xB0,0x0A,0xA0,0x09,0x90,
94: 0x08,0x80,0x07,0x70,0x06,0x60,0x05,0x50,
95: 0x04,0x40,0x03,0x30,0x02,0x20,0x01,0x10 } },
96:
97: { "0x155555555555555555555555", 3,1, 4,1, 1,
98: { 0xD5,0x55,0x55,0x55, 0xAA,0xAA,0xAA,0xAA, 0xD5,0x55,0x55,0x55 } },
99: { "0x155555555555555555555555", 3,-1, 4,1, 1,
100: { 0xD5,0x55,0x55,0x55, 0xAA,0xAA,0xAA,0xAA, 0xD5,0x55,0x55,0x55 } },
101: { "0x155555555555555555555555", 3,1, 4,-1, 1,
102: { 0x55,0x55,0x55,0xD5, 0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0xD5 } },
103: { "0x155555555555555555555555", 3,-1, 4,-1, 1,
104: { 0x55,0x55,0x55,0xD5, 0xAA,0xAA,0xAA,0xAA, 0x55,0x55,0x55,0xD5 } },
105: };
106:
107: char buf[sizeof(data[0].src) + sizeof (mp_limb_t)];
108: char *src;
109: size_t align;
110: int i;
111: mpz_t got, want;
112:
113: mpz_init (got);
114: mpz_init (want);
115:
116: for (i = 0; i < numberof (data); i++)
117: {
118: for (align = 0; align < sizeof (mp_limb_t); align++)
119: {
120: mpz_set_str_or_abort (want, data[i].want, 0);
121: src = buf + align;
122: memcpy (src, data[i].src, data[i].count * data[i].size);
123:
124: mpz_set_ui (got, 0L);
125: mpz_import (got, data[i].count, data[i].order,
126: data[i].size, data[i].endian, data[i].nail, src);
127:
128: MPZ_CHECK_FORMAT (got);
129: if (mpz_cmp (got, want) != 0)
130: {
131: printf ("wrong at data[%d]\n", i);
132: printf (" count=%u order=%d size=%u endian=%d nail=%u align=%u\n",
133: data[i].count, data[i].order,
134: data[i].size, data[i].endian, data[i].nail,
135: align);
136: mpz_trace (" got ", got);
137: mpz_trace (" want", want);
138: abort ();
139: }
140: }
141: }
142: mpz_clear (got);
143: mpz_clear (want);
144: }
145:
146:
147: int
148: main (void)
149: {
150: tests_start ();
151:
152: mp_trace_base = -16;
153: check_data ();
154:
155: tests_end ();
156: exit (0);
157: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>