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 @@
0
+//
1
+//  mulle_standalone_container.c
2
+//  mulle-container
3
+//
4
+//  Created by Nat! on 07.04.16.
5
+//  Copyright © 2016 Mulle kybernetiK. All rights reserved.
6
+//
7
+
8
+#include "mulle_vararg.h"
9
+
10
+#include <stdint.h>
11
+
12
+
13
+// food for the linker
14
+uint32_t   mulle_vararg_standalone_version = MULLE_VARARG_VERSION;
0 15
new file mode 100755
... ...
@@ -0,0 +1,7 @@
0
+#! /bin/sh
1
+
2
+LIBRARY_SHORTNAME="mulle_vararg"
3
+
4
+. "../mulle-tests/test-c-common.sh"
5
+. "../mulle-tests/test-tools-common.sh"
6
+. "../mulle-tests/build-test-common.sh"
0 7
new file mode 100755
... ...
@@ -0,0 +1,13 @@
0
+#!/usr/bin/env bash
1
+#  run-test.sh
2
+#  MulleObjC
3
+#
4
+#  Created by Nat! on 01.11.13.
5
+#  Copyright (c) 2013 Mulle kybernetiK. All rights reserved.
6
+#  (was run-mulle-scion-test)
7
+
8
+LIBRARY_SHORTNAME="mulle_vararg"
9
+
10
+. "../mulle-tests/test-c-common.sh"
11
+. "../mulle-tests/test-tools-common.sh"
12
+. "../mulle-tests/run-test-common.sh"
0 13
new file mode 100644
... ...
@@ -0,0 +1 @@
0
+Because char gets promoted to int.
0 1
new file mode 100644
... ...
@@ -0,0 +1 @@
0
+18
0 1
new file mode 100644
... ...
@@ -0,0 +1,26 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   double   a;
7
+   char   b;
8
+} value =
9
+{
10
+   -1848,
11
+   18
12
+};
13
+
14
+
15
+int   main( voids)
16
+{
17
+   mulle_vararg_list   list;
18
+
19
+   mulle_vararg_start( list, value.a);
20
+
21
+   printf( "%d\n", mulle_vararg_next_integer( list, char));
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 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   int   a;
7
+   char   b;
8
+} value =
9
+{
10
+   -1848,
11
+   18
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, char));
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 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   long long   a;
7
+   char   b;
8
+} value =
9
+{
10
+   -1848,
11
+   18
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, char));
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 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   void  *a;
7
+   char   b;
8
+} value =
9
+{
10
+   -1848,
11
+   18
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, char));
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 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   double   a;
7
+   double  b;
8
+} value =
9
+{
10
+   -1848,
11
+   18.48
12
+};
13
+
14
+
15
+int   main( void)
16
+{
17
+   mulle_vararg_list   list;
18
+
19
+   mulle_vararg_start( list, value.a);
20
+
21
+   printf( "%.2f\n", mulle_vararg_next_fp( list, double));
22
+
23
+   mulle_vararg_end( list);
24
+   return( 0);
25
+}
0 26
new file mode 100644
... ...
@@ -0,0 +1,26 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   int      a;
7
+   double   b;
8
+} value =
9
+{
10
+   0,
11
+   18.48
12
+};
13
+
14
+
15
+int   main( void)
16
+{
17
+   mulle_vararg_list   list;
18
+
19
+   mulle_vararg_start( list, value.a);
20
+
21
+   printf( "%.2f\n", mulle_vararg_next_fp( list, double));
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 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   long long   a;
7
+   double      b;
8
+} value =
9
+{
10
+   -1848,
11
+   18.48
12
+};
13
+
14
+
15
+int   main( void)
16
+{
17
+   mulle_vararg_list   list;
18
+
19
+   mulle_vararg_start( list, value.a);
20
+
21
+   printf( "%.2f\n", mulle_vararg_next_fp( list, double));
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 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   void    *a;
7
+   double  b;
8
+} value =
9
+{
10
+   -1848,
11
+   18.48
12
+};
13
+
14
+
15
+int   main( void)
16
+{
17
+   mulle_vararg_list   list;
18
+
19
+   mulle_vararg_start( list, value.a);
20
+
21
+   printf( "%.2f\n", mulle_vararg_next_fp( list, double));
22
+
23
+   mulle_vararg_end( list);
24
+   return( 0);
25
+}
0 26
new file mode 100644
... ...
@@ -0,0 +1,26 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   char  a;
7
+   int   b;
8
+} value =
9
+{
10
+   -18,
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 @@
0
+1848
0 1
new file mode 100644
... ...
@@ -0,0 +1,26 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   double   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 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   int   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 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   long long   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
new file mode 100644
... ...
@@ -0,0 +1,25 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+struct
4
+{
5
+   void  *a;
6
+   int    b;
7
+} value =
8
+{
9
+   -1848,
10
+   1848
11
+};
12
+
13
+
14
+int   main( void)
15
+{
16
+   mulle_vararg_list   list;
17
+
18
+   mulle_vararg_start( list, value.a);
19
+
20
+   printf( "%d\n", mulle_vararg_next_integer( list, int));
21
+
22
+   mulle_vararg_end( list);
23
+   return( 0);
24
+}
0 25
\ No newline at end of file
1 26
new file mode 100644
... ...
@@ -0,0 +1,26 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   double      a;
7
+   long long   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( "%lld\n", mulle_vararg_next_integer( list, long long));
22
+
23
+   mulle_vararg_end( list);
24
+   return( 0);
25
+}
0 26
new file mode 100644
... ...
@@ -0,0 +1,26 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   int         a;
7
+   long long   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( "%lld\n", mulle_vararg_next_integer( list, long long));
22
+
23
+   mulle_vararg_end( list);
24
+   return( 0);
25
+}
0 26
new file mode 100644
... ...
@@ -0,0 +1,26 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   long long   a;
7
+   long long   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( "%lld\n", mulle_vararg_next_integer( list, long long));
22
+
23
+   mulle_vararg_end( list);
24
+   return( 0);
25
+}
0 26
new file mode 100644
... ...
@@ -0,0 +1,26 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   void       *a;
7
+   long long   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( "%lld\n", mulle_vararg_next_integer( list, long long));
22
+
23
+   mulle_vararg_end( list);
24
+   return( 0);
25
+}
0 26
new file mode 100644
... ...
@@ -0,0 +1,26 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   double  a;
7
+   void    *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( "%ld\n", (long) (intptr_t) mulle_vararg_next_pointer( list, void *));
22
+
23
+   mulle_vararg_end( list);
24
+   return( 0);
25
+}
0 26
new file mode 100644
... ...
@@ -0,0 +1,26 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   int     a;
7
+   void    *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( "%ld\n", (long) (intptr_t) mulle_vararg_next_pointer( list, void *));
22
+
23
+   mulle_vararg_end( list);
24
+   return( 0);
25
+}
0 26
new file mode 100644
... ...
@@ -0,0 +1,26 @@
0
+#include <mulle_vararg/mulle_vararg.h>
1
+#include <stdio.h>
2
+
3
+
4
+struct
5
+{
6
+   long long  a;
7
+   void       *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( "%ld\n", (long) (intptr_t) mulle_vararg_next_pointer( list, void *));
22
+
23
+   mulle_vararg_end( list);
24
+   return( 0);
25
+}