Adding copyright notices to most files. Also add readme file, and some
[jitcs.git] / tests / test_fnctypeinfo.cpp
blobc7f1e711f28c71d48d472fdab5d92a01d1e6038a
1 //===-- tests/test_fnctypeinfo.cpp ------------------------------*- C++ -*-===//
2 // Test of functions deconstructing function types.
3 //
4 // Copyright (C) 2013-2014 Dirk Steinke.
5 // See copyright and license notice in COPYRIGHT or include/jitcs.h
6 //===----------------------------------------------------------------------===//
8 #include "jitcs_fnctypeinfo.h"
9 #include "unittest.h"
11 using namespace jitcs;
13 static bool isIntOrPtrInt(FTTypeId id) {
14 return id == FTT_Int || id == FTT_PtrInt;
18 static void test(UnitTest& t) {
19 typedef void (__cdecl *F0)();
20 typedef int (__stdcall *F2)(int, int*);
21 typedef int* (__fastcall *F8)(int, uint, iptr, uptr, char*, const short*,
22 long&, const int&);
23 t.check("GetFTSubType/1", GetFTSubType<F0>::Value == FTS_CDecl);
24 t.check("GetFTSubType/2", GetFTSubType<F2>::Value == FTS_StdCall);
25 t.check("GetFTSubType/3", GetFTSubType<F8>::Value == FTS_FastCall);
27 t.check("GetFTParamCount/1", GetFTParamCount<F0>::Value == 0);
28 t.check("GetFTParamCount/2", GetFTParamCount<F2>::Value == 2);
29 t.check("GetFTParamCount/3", GetFTParamCount<F8>::Value == 8);
31 t.check("GetFTResultId/1", GetFTResultId<F0>::Value == FTT_Void);
32 t.check("GetFTResultId/2", isIntOrPtrInt(GetFTResultId<F2>::Value));
33 t.check("GetFTResultId/3", GetFTResultId<F8>::Value == FTT_Ptr);
35 t.check("GetFTParamId/1", GetFTParamId<F0, 0>::Value == FTT_Void);
36 t.check("GetFTParamId/2", isIntOrPtrInt(GetFTParamId<F2, 0>::Value));
37 t.check("GetFTParamId/3", GetFTParamId<F2, 1>::Value == FTT_Ptr);
38 t.check("GetFTParamId/4", isIntOrPtrInt(GetFTParamId<F8, 0>::Value));
39 t.check("GetFTParamId/5", isIntOrPtrInt(GetFTParamId<F8, 1>::Value));
40 t.check("GetFTParamId/6", isIntOrPtrInt(GetFTParamId<F8, 2>::Value));
41 t.check("GetFTParamId/7", isIntOrPtrInt(GetFTParamId<F8, 3>::Value));
42 t.check("GetFTParamId/8", GetFTParamId<F8, 4>::Value == FTT_Ptr);
43 t.check("GetFTParamId/9", GetFTParamId<F8, 5>::Value == FTT_Ptr);
44 t.check("GetFTParamId/10", GetFTParamId<F8, 6>::Value == FTT_Ptr);
45 t.check("GetFTParamId/11", GetFTParamId<F8, 7>::Value == FTT_Ptr);
48 static UnitTestRun _("FncTypeInfo", test);