aboutsummaryrefslogtreecommitdiffstats
path: root/longbow/src/LongBow/longBow_Config.h
blob: 003497b4fdf2de16e8483ffa6d0884a481608587 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file longBow_Config.h
 * @ingroup internals
 * @brief Support for LongBow Configuration
 *
 */
#ifndef LONGBOWCONFIGURATION_H_
#define LONGBOWCONFIGURATION_H_
#include <stdbool.h>
#include <stdint.h>

struct longbow_configuration;

/**
 * @typedef LongBowConfig
 * @brief The LongBow Configuration
 */
typedef struct longbow_configuration LongBowConfig;

/**
 * Destroy a LongBowConfig instance.
 *
 * @param [in,out] configPtr A pointer to a LongBowConfig instance pointer.
 */
void longBowConfig_Destroy(LongBowConfig **configPtr);

/**
 * Create a LongBowConfig structure instance from the given array of parameters.
 *
 * The function parses argv style arguments and composes a LongBowConfig structure.
 *
 * The argv-style arguments may include parameters not related to creating a LongBowConfig structure.
 *
 * For example, the arguments may only be `--help` and prints a help message but doesn't create a `LongBowConfig` structure.
 *
 * @param [in] argc The number of elements in the `argv` array.
 * @param [in] argv An array of nul-terminated C strings.
 * @param [in] mainFileName The string printed for the `--main` option.
 *
 * @return non-NULL A LongBowConfig structure instance suitable for running a test
 * @return NULL Nothing suitable for running a test (not an error).
 */
LongBowConfig *longBowConfig_Create(int argc, char *argv[], const char *mainFileName);

/**
 * Get a property stored in the configuration.
 * @param [in] config A pointer to a valid LongBowConfig instance.
 * @param [in] format A pointer to a valid, nul-terminated format string.
 *
 * @return non-NULL A pointer to nul-terminated, C string.
 */
const char *longBowConfig_GetProperty(const LongBowConfig *config, const char *format, ...);

/**
 * Set the property @p name to @p value
 *
 * @param [in] config A pointer to a valid LongBowConfig instance.
 *
 * @return true
 * @return true
 */
bool longBowConfig_SetProperty(const LongBowConfig *config, const char *name, const char *value);

/**
 * Get the property @p name interpreted as a 32-bit integer.
 *
 * @param [in] config A pointer to a valid LongBowConfig instance.
 *
 * @return The property @p name interpreted as a 32-bit integer.
 */
uint32_t longBowConfig_GetUint32(const LongBowConfig *config, uint32_t defaultValue, const char *format, ...);

/**
 * Get the value of the configuration property named by the formatted property name.
 * If the given LongBowConfig instance is not available, or the property is not present, the default value is returned.
 *
 * @param [in] config A pointer to a valid LongBowConfig instance.
 * @param [in] defaultValue Either true or false.
 * @param [in] format A printf format string followed by appropriate parameters used to construct the property name.
 *
 * @return true The property was present with the value true, or the property was not present and the default value is true.
 * @return false The property was present with the value false, or the property was not present and the default value is false.
 */
bool longBowConfig_GetBoolean(const LongBowConfig *config, bool defaultValue, const char *format, ...);

/**
 * Return `true` if the given `LongBowConfig` instance specifies that test cases are to be run in a sub-process.
 *
 * @param [in] config A pointer to a valid LongBowConfig instance.
 * @return true if the given specification stipulates tests are to run in a sub-process.
 */
bool longBowConfig_IsRunForked(const LongBowConfig *config);

/**
 * Indicate if the given configuration is specifying the 'trace' flag.
 *
 * @param [in] config A pointer to a valid LongBowConfig instance.
 *
 * @return true The given configuration is specifying the 'trace' flag.
 * @return false The given configuration is not specifying the 'trace' flag.
 *
 * Example:
 * @code
 * if (longBowConfig_IsTrace(longBowRunner_GetConfiguration(testRunner)) {
 *     longBowTrace_Report(testRunner->configuration);
 * }
 * @endcode
 */
bool longBowConfig_IsTrace(const LongBowConfig *config);

#endif // LONGBOWCONFIGURATION_H_