File: sizes.c

package info (click to toggle)
mono-reference-assemblies 3.12.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 604,240 kB
  • ctags: 625,505
  • sloc: cs: 3,967,741; xml: 2,793,081; ansic: 418,042; java: 60,435; sh: 14,833; makefile: 11,576; sql: 7,956; perl: 1,467; cpp: 1,446; yacc: 1,203; python: 598; asm: 422; sed: 16; php: 1
file content (108 lines) | stat: -rw-r--r-- 2,348 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * Tests to ensure that our type definitions are correct
 *
 * These depend on -Werror, -Wall being set to catch the build error.
 */
#include <stdio.h>
#ifndef _MSC_VER
#include <stdint.h>
#endif
#include <string.h>
#include <glib.h>
#include "test.h"

RESULT
test_formats ()
{
	char buffer [1024];
	gsize a = 1;
	
	sprintf (buffer, "%" G_GSIZE_FORMAT, a);

	return NULL;
}

RESULT
test_ptrconv ()
{
	int iv, iv2;
	unsigned int uv, uv2;
	gpointer ptr;

	iv = G_MAXINT32;
	ptr = GINT_TO_POINTER (iv);
	iv2 = GPOINTER_TO_INT (ptr);
	if (iv != iv2)
		return FAILED ("int to pointer and back conversions fail %d != %d", iv, iv2);

	iv = G_MININT32;
	ptr = GINT_TO_POINTER (iv);
	iv2 = GPOINTER_TO_INT (ptr);
	if (iv != iv2)
		return FAILED ("int to pointer and back conversions fail %d != %d", iv, iv2);

	iv = 1;
	ptr = GINT_TO_POINTER (iv);
	iv2 = GPOINTER_TO_INT (ptr);
	if (iv != iv2)
		return FAILED ("int to pointer and back conversions fail %d != %d", iv, iv2);

	iv = -1;
	ptr = GINT_TO_POINTER (iv);
	iv2 = GPOINTER_TO_INT (ptr);
	if (iv != iv2)
		return FAILED ("int to pointer and back conversions fail %d != %d", iv, iv2);

	iv = 0;
	ptr = GINT_TO_POINTER (iv);
	iv2 = GPOINTER_TO_INT (ptr);
	if (iv != iv2)
		return FAILED ("int to pointer and back conversions fail %d != %d", iv, iv2);

	uv = 0;
	ptr = GUINT_TO_POINTER (uv);
	uv2 = GPOINTER_TO_UINT (ptr);
	if (uv != uv2)
		return FAILED ("uint to pointer and back conversions fail %u != %d", uv, uv2);
	
	uv = 1;
	ptr = GUINT_TO_POINTER (uv);
	uv2 = GPOINTER_TO_UINT (ptr);
	if (uv != uv2)
		return FAILED ("uint to pointer and back conversions fail %u != %d", uv, uv2);

	uv = UINT32_MAX;
	ptr = GUINT_TO_POINTER (uv);
	uv2 = GPOINTER_TO_UINT (ptr);
	if (uv != uv2)
		return FAILED ("uint to pointer and back conversions fail %u != %d", uv, uv2);

	return NULL;
	
}

typedef struct {
	int a;
	int b;
} my_struct;

RESULT
test_offset ()
{
	if (G_STRUCT_OFFSET (my_struct, a) != 0)
		return FAILED ("offset of a is not zero");
	
	if (G_STRUCT_OFFSET (my_struct, b) != 4 && G_STRUCT_OFFSET (my_struct, b) != 8)
		return FAILED ("offset of b is 4 or 8, macro might be busted");

	return OK;
}

static Test size_tests [] = {
	{"formats", test_formats},
	{"ptrconv", test_ptrconv},
	{"g_struct_offset", test_offset},
	{NULL, NULL}
};

DEFINE_TEST_GROUP_INIT(size_tests_init, size_tests)