1 /* Test mpz_inp_binary and mpz_out_binary.
3 We write and read back some test strings, and both compare
4 the numerical result, and make sure the pattern on file is
5 what we expect. The latter is important for compatibility
6 between machines with different word sizes. */
13 test (str, binary_len, binary_str)
22 mpz_init_set_str (x, str, 0);
25 fseek (file, 0, SEEK_SET);
26 mpz_out_binary (file, x);
27 n_written = ftell (file);
28 if (n_written != binary_len)
31 fseek (file, 0, SEEK_SET);
32 mpz_inp_binary (y, file);
33 if (n_written != ftell (file))
35 if (mpz_cmp (x, y) != 0)
38 fseek (file, 0, SEEK_SET);
39 fread (buf, n_written, 1, file);
40 if (memcmp (buf, binary_str, binary_len) != 0)
48 file = fopen ("xtmpfile", "w+");
54 "\000\000\000\001\001");
56 "\000\000\000\002\001\043");
57 test ("0xdeadbeef", 8,
58 "\000\000\000\004\336\255\276\357");
59 test ("0xbabefaced", 9,
60 "\000\000\000\005\013\253\357\254\355");
61 test ("0x123456789facade0", 12,
62 "\000\000\000\010\022\064\126\170\237\254\255\340");
65 "\377\377\377\377\001");
67 "\377\377\377\376\001\043");
68 test ("-0xdeadbeef", 8,
69 "\377\377\377\374\336\255\276\357");
70 test ("-0xbabefaced", 9,
71 "\377\377\377\373\013\253\357\254\355");
72 test ("-0x123456789facade0", 12,
73 "\377\377\377\370\022\064\126\170\237\254\255\340");