Browse code

Add tests to vararg

Nat! authored on 11-09-2016 16:56:56
Showing 30 changed files
... ...
@@ -1 +1,3 @@
1 1
 https://www.mulle-kybernetik.com/repositories/mulle-configuration
2
+https://www.mulle-kybernetik.com/repositories/mulle-tests
3
+
... ...
@@ -11,3 +11,5 @@ dependencies/
11 11
 mulle-configuration/
12 12
 tmp/
13 13
 research/
14
+addictions/
15
+mulle-tests/
... ...
@@ -31,3 +31,46 @@ INSTALL(TARGETS mulle_vararg DESTINATION "lib")
31 31
 INSTALL(FILES ${HEADERS} DESTINATION "include/mulle_vararg")
32 32
 
33 33
 
34
+#
35
+# standalone shared library (for tests)
36
+#
37
+
38
+if( MSVC)
39
+  set( DEF_FILE mulle_vararg_standalone.def)
40
+  set_source_files_properties( ${DEF_FILE} PROPERTIES HEADER_FILE_ONLY TRUE)
41
+  set( CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS OFF)
42
+  set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEF:${DEF_FILE}")
43
+  # /NODEFAULTLIB:MSVCRT")
44
+endif()
45
+
46
+
47
+add_library( mulle_vararg_standalone SHARED
48
+src/mulle_vararg_standalone.c
49
+${DEF_FILE}
50
+)
51
+
52
+add_dependencies( mulle_vararg_standalone mulle_vararg)
53
+
54
+
55
+set( DEPENDENCY_LIBRARIES
56
+)
57
+
58
+
59
+if( MSVC)
60
+   add_custom_command( OUTPUT ${DEF_FILE}
61
+                       COMMAND mulle-mingw-dumpdef.bat -o "${DEF_FILE}" --prefix "mulle" ${DEPENDENCY_LIBRARIES} $<TARGET_FILE:mulle_vararg>
62
+                       DEPENDS "${DEPENDENCY_LIBRARIES}" mulle_vararg
63
+                       VERBATIM)
64
+endif()
65
+
66
+
67
+TARGET_LINK_LIBRARIES( mulle_vararg_standalone
68
+${BEGIN_ALL_LOAD}
69
+mulle_vararg
70
+${DEPENDENCY_LIBRARIES}
71
+${END_ALL_LOAD}
72
+)
73
+
74
+
75
+INSTALL( TARGETS mulle_vararg_standalone DESTINATION "lib")
76
+
... ...
@@ -69,18 +69,18 @@ while( 0)
69 69
 static inline char  *_mulle_vararg_int_aligned_pointer( mulle_vararg_list *args, size_t size, unsigned int align)
70 70
 {
71 71
    char   *q;
72
-   
72
+
73 73
    if( size < sizeof( int))
74 74
    {
75 75
       size  = sizeof( int);
76 76
       align = alignof( struct{ int x; });  // weirdness for i386
77 77
    }
78
-   
78
+
79 79
    q       = mulle_align_pointer( args->p, align);
80 80
    args->p = &q[ size];
81 81
    return( q);
82 82
 }
83
-   
83
+
84 84
 
85 85
 #define mulle_vararg_next_integer( args, type)                                                                \
86 86
    (sizeof( type) < sizeof( int)                                                                              \
... ...
@@ -91,7 +91,7 @@ static inline char  *_mulle_vararg_int_aligned_pointer( mulle_vararg_list *args,
91 91
 static inline char  *_mulle_vararg_aligned_pointer( mulle_vararg_list *args, unsigned int align)
92 92
 {
93 93
    char   *q;
94
-   
94
+
95 95
    q       = mulle_align_pointer( args->p, align);
96 96
    args->p = &q[ sizeof( void *)];
97 97
    return( q);
... ...
@@ -119,13 +119,13 @@ static inline char  *_mulle_vararg_aligned_pointer( mulle_vararg_list *args, uns
119 119
 static inline char  *_mulle_vararg_double_aligned_pointer( mulle_vararg_list *args, size_t size, unsigned int align)
120 120
 {
121 121
    char   *q;
122
-   
122
+
123 123
    if( size < sizeof( double))
124 124
    {
125 125
       size  = sizeof( double);
126 126
       align = alignof( struct{ double x; });  // weirdness for i386
127 127
    }
128
-   
128
+
129 129
    q       = mulle_align_pointer( args->p, align);
130 130
    args->p = &q[ size];
131 131
    return( q);
... ...
@@ -165,8 +165,8 @@ static inline size_t    mulle_vararg_count( mulle_vararg_list args, void *object
165 165
       ++count;
166 166
       p = mulle_vararg_next_pointer( args, void *);
167 167
    }
168
-   
168
+
169 169
    return( count);
170 170
 }
171
-   
171
+
172 172
 #endif /* mulle_vararg_h */
173 173
new file mode 100644
... ...
@@ -0,0 +1,15 @@
1
+//
2
+//  mulle_standalone_container.c
3
+//  mulle-container
4
+//
5
+//  Created by Nat! on 07.04.16.
6
+//  Copyright © 2016 Mulle kybernetiK. All rights reserved.
7
+//
8
+
9
+#include "mulle_vararg.h"
10
+
11
+#include <stdint.h>
12
+
13
+
14
+// food for the linker
15
+uint32_t   mulle_vararg_standalone_version = MULLE_VARARG_VERSION;
0 16
new file mode 100755
... ...
@@ -0,0 +1,7 @@
1
+#! /bin/sh
2
+
3
+LIBRARY_SHORTNAME="mulle_vararg"
4
+
5
+. "../mulle-tests/test-c-common.sh"
6
+. "../mulle-tests/test-tools-common.sh"
7
+. "../mulle-tests/build-test-common.sh"
0 8
new file mode 100755
... ...
@@ -0,0 +1,13 @@
1
+#!/usr/bin/env bash
2
+#  run-test.sh
3
+#  MulleObjC
4
+#
5
+#  Created by Nat! on 01.11.13.
6
+#  Copyright (c) 2013 Mulle kybernetiK. All rights reserved.
7
+#  (was run-mulle-scion-test)
8
+
9
+LIBRARY_SHORTNAME="mulle_vararg"
10
+
11
+. "../mulle-tests/test-c-common.sh"
12
+. "../mulle-tests/test-tools-common.sh"
13
+. "../mulle-tests/run-test-common.sh"
0 14
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+Because char gets promoted to int.
0 2
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+18
0 2
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   double   a;
8
+   char   b;
9
+} value =
10
+{
11
+   -1848,
12
+   18
13
+};
14
+
15
+
16
+int   main( voids)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%d\n", mulle_vararg_next_integer( list, char));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
\ No newline at end of file
1 28
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   int   a;
8
+   char   b;
9
+} value =
10
+{
11
+   -1848,
12
+   18
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%d\n", mulle_vararg_next_integer( list, char));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
\ No newline at end of file
1 28
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   long long   a;
8
+   char   b;
9
+} value =
10
+{
11
+   -1848,
12
+   18
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%d\n", mulle_vararg_next_integer( list, char));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
\ No newline at end of file
1 28
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   void  *a;
8
+   char   b;
9
+} value =
10
+{
11
+   -1848,
12
+   18
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%d\n", mulle_vararg_next_integer( list, char));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
\ No newline at end of file
1 28
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   double   a;
8
+   double  b;
9
+} value =
10
+{
11
+   -1848,
12
+   18.48
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%.2f\n", mulle_vararg_next_fp( list, double));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   int      a;
8
+   double   b;
9
+} value =
10
+{
11
+   0,
12
+   18.48
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%.2f\n", mulle_vararg_next_fp( list, double));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
\ No newline at end of file
1 28
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   long long   a;
8
+   double      b;
9
+} value =
10
+{
11
+   -1848,
12
+   18.48
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%.2f\n", mulle_vararg_next_fp( list, double));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
\ No newline at end of file
1 28
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   void    *a;
8
+   double  b;
9
+} value =
10
+{
11
+   -1848,
12
+   18.48
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%.2f\n", mulle_vararg_next_fp( list, double));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   char  a;
8
+   int   b;
9
+} value =
10
+{
11
+   -18,
12
+   1848
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%d\n", mulle_vararg_next_integer( list, int));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
\ No newline at end of file
1 28
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+1848
0 2
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   double   a;
8
+   int      b;
9
+} value =
10
+{
11
+   -1848,
12
+   1848
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%d\n", mulle_vararg_next_integer( list, int));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
\ No newline at end of file
1 28
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   int   a;
8
+   int   b;
9
+} value =
10
+{
11
+   -1848,
12
+   1848
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%d\n", mulle_vararg_next_integer( list, int));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
\ No newline at end of file
1 28
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   long long   a;
8
+   int         b;
9
+} value =
10
+{
11
+   -1848,
12
+   1848
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%d\n", mulle_vararg_next_integer( list, int));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
new file mode 100644
... ...
@@ -0,0 +1,25 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+struct
5
+{
6
+   void  *a;
7
+   int    b;
8
+} value =
9
+{
10
+   -1848,
11
+   1848
12
+};
13
+
14
+
15
+int   main( void)
16
+{
17
+   mulle_vararg_list   list;
18
+
19
+   mulle_vararg_start( list, value.a);
20
+
21
+   printf( "%d\n", mulle_vararg_next_integer( list, int));
22
+
23
+   mulle_vararg_end( list);
24
+   return( 0);
25
+}
0 26
\ No newline at end of file
1 27
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   double      a;
8
+   long long   b;
9
+} value =
10
+{
11
+   -1848,
12
+   1848
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%lld\n", mulle_vararg_next_integer( list, long long));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   int         a;
8
+   long long   b;
9
+} value =
10
+{
11
+   -1848,
12
+   1848
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%lld\n", mulle_vararg_next_integer( list, long long));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   long long   a;
8
+   long long   b;
9
+} value =
10
+{
11
+   -1848,
12
+   1848
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%lld\n", mulle_vararg_next_integer( list, long long));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   void       *a;
8
+   long long   b;
9
+} value =
10
+{
11
+   -1848,
12
+   1848
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%lld\n", mulle_vararg_next_integer( list, long long));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   double  a;
8
+   void    *b;
9
+} value =
10
+{
11
+   -1848,
12
+   1848
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%ld\n", (long) (intptr_t) mulle_vararg_next_pointer( list, void *));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   int     a;
8
+   void    *b;
9
+} value =
10
+{
11
+   -1848,
12
+   1848
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%ld\n", (long) (intptr_t) mulle_vararg_next_pointer( list, void *));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}
0 27
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+#include <mulle_vararg/mulle_vararg.h>
2
+#include <stdio.h>
3
+
4
+
5
+struct
6
+{
7
+   long long  a;
8
+   void       *b;
9
+} value =
10
+{
11
+   -1848,
12
+   1848
13
+};
14
+
15
+
16
+int   main( void)
17
+{
18
+   mulle_vararg_list   list;
19
+
20
+   mulle_vararg_start( list, value.a);
21
+
22
+   printf( "%ld\n", (long) (intptr_t) mulle_vararg_next_pointer( list, void *));
23
+
24
+   mulle_vararg_end( list);
25
+   return( 0);
26
+}