MoonUnit
 All Data Structures Variables Enumerations Enumerator Groups Pages
loader.h
1 /*
2  * Copyright (c) 2007-2008, Brian Koropoff
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the Moonunit project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY BRIAN KOROPOFF ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL BRIAN KOROPOFF BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __MU_LOADER_H__
29 #define __MU_LOADER_H__
30 
31 #include <moonunit/internal/boilerplate.h>
32 #include <moonunit/error.h>
33 #include <moonunit/plugin.h>
34 #include <moonunit/option.h>
35 #include <moonunit/test.h>
36 #include <sys/types.h>
37 
38 C_BEGIN_DECLS
39 
40 struct MuLibrary;
41 
42 typedef void (*MuLogCallback)(struct MuLogEvent const* event, void* data);
43 
44 typedef struct MuLoader
45 {
46  struct MuPlugin* plugin;
47  MuOption* options;
48  // Determines if a library can be opened by this loader
49  bool (*can_open) (struct MuLoader*, const char* path);
50  // Opens a library and returns a handle
51  struct MuLibrary* (*open) (struct MuLoader*, const char* path, MuError** err);
52  // Returns a null-terminated list of unit tests
53  struct MuTest** (*get_tests) (struct MuLoader*, struct MuLibrary* handle);
54  // Frees a list of unit tests that had been returned by get_tests
55  void (*free_tests) (struct MuLoader*, struct MuLibrary* handle, struct MuTest** list);
56  // Closes a library
57  void (*close) (struct MuLoader*, struct MuLibrary* handle);
58  // Get name of a library
59  const char* (*library_name) (struct MuLoader*, struct MuLibrary* handle);
60  // Get the name of a test
61  const char* (*test_name) (struct MuLoader*, struct MuTest*);
62  // Get the suite of a test
63  const char* (*test_suite) (struct MuLoader*, struct MuTest*);
64  // Dispatch a single test
65  struct MuTestResult* (*dispatch)(struct MuLoader*, struct MuTest*, MuLogCallback, void*, MuLogLevel);
66  // Free the result of a unit test
67  void (*free_result)(struct MuLoader*, struct MuTestResult*);
68  /* Runs the constructor for a library, which does any needed *one-time* setup */
69  void (*construct) (struct MuLoader*, struct MuLibrary* handle, MuError** err);
70  /* Runs the destructor for a library, which does any needed *one-time* teardown */
71  void (*destruct) (struct MuLoader*, struct MuLibrary* handle, MuError** err);
72 } MuLoader;
73 
74 bool mu_loader_can_open(MuLoader* loader, const char* path);
75 struct MuLibrary* mu_loader_open(MuLoader* loader, const char* path, MuError** err);
76 void mu_loader_set_option(MuLoader* loader, const char *name, ...);
77 void mu_loader_set_option_string(MuLoader* loader, const char *name, const char *value);
78 MuType mu_loader_option_type(MuLoader* loader, const char *name);
79 
80 C_END_DECLS
81 
82 #endif
Definition: library.h:38
Definition: error.h:60
Definition: option.h:35
MuLogLevel
Definition: test.h:133
Definition: loader.h:44
Definition: plugin.h:37