1/*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LLVM_LICENSE_HEADER@
5 */
6
7/*
8 *  basic.c
9 *  ClosureTest
10 *  This is pretty much the test runner code.
11 *
12 *  Created by Blaine Garst on 1/25/08.
13 *  Copyright 2008 __MyCompanyName__. All rights reserved.
14 *
15 */
16
17#include "driver.h"
18
19
20
21// pretend this is the GCD do_work code
22void callVoidVoid(void *arg) {
23   // assume this a GCD style fully bound closure
24   struct Block_basic *aBlock = (struct Block_basic *)arg;
25   aBlock->Block_invoke(aBlock);  // aBlock()
26}
27
28int GlobalInt;
29void setGlobalInt(int value) { GlobalInt = value; }
30int getGlobalInt() { int tmp = GlobalInt; GlobalInt = 0; return tmp; }
31
32
33
34int main(int argc, char *argv[]) {
35
36    int errors = 0;
37    int verbose = VERBOSE;
38
39    if (verbose) printf("Handling hand generated test cases\n");
40    errors += parameters_example(verbose);
41    errors += result_value_example(verbose);
42    errors += imports_example(verbose);
43    //errors += imports_example2(verbose);
44
45    errors += import_byref(verbose);
46    errors += import_byref_interim(verbose);
47    errors += import_global(verbose);
48
49#if __BLOCKS__
50    errors += test_blocks(verbose);
51
52    if (verbose) printf("\nhandling compiler generated test cases\n");
53    errors += result_value_example_real(verbose);
54    errors += parameters_example_real(verbose);
55    errors += import_global_real(verbose);
56    errors += imports_example_real(verbose);
57    //errors += imports_example2_real(verbose);
58
59    errors += import_byref_real(verbose);
60    errors += import_byref_interim_real(verbose);
61
62    errors += test_objc(verbose);
63
64
65#endif
66    return errors;
67}
68
69void aDoNothingFunction() {
70}
71
72// error handling
73int error_found(const char *name, int globalValue, int desiredValue, int verbose) {
74   if (globalValue != desiredValue) {
75        printf("%s globalValue %d, should be %d\n", name, globalValue, desiredValue);
76        aDoNothingFunction();
77        return 1;
78    }
79    else {
80        if (verbose) printf("%s saw correct values\n", name);
81    }
82    return 0;
83}
84