libmpm

morphux C package management library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/libmpm

commit a587798b423db7f0965b8f491c2ebeeb672bf77c
parent b53642bfbe0d0c9f05bdae43c7926ec8896a05ae
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Wed, 25 Jan 2017 18:48:05 +0100

Add(Flags): Now supporting internal flags:

Add tests with it too

Diffstat:
Ainc/flags.h | 29+++++++++++++++++++++++++++++
Minc/libmpm.h | 3+--
Asrc/flags.c | 43+++++++++++++++++++++++++++++++++++++++++++
Mtests/main.c | 8+-------
Mtests/test.h | 2++
Atests/tests_flags.c | 19+++++++++++++++++++
6 files changed, 95 insertions(+), 9 deletions(-)

diff --git a/inc/flags.h b/inc/flags.h @@ -0,0 +1,29 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* 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. * +\******************************************************************************/ + +#ifndef FLAGS_H +# define FLAGS_H +# include <morphux.h> + +enum { + MPM_VERBOSE_LEVEL = 0, + MPM_LAST /* Always keep this one last */ +}; + +void mpm_set_flag(u8_t flag, u8_t val); +u8_t mpm_get_flag(u8_t flag); + +#endif /* FLAGS_H */ diff --git a/inc/libmpm.h b/inc/libmpm.h @@ -18,7 +18,6 @@ # define LIBMPM_H # include <morphux.h> - -void useless(void); +# include <flags.h> #endif /* LIBMPM_H */ diff --git a/src/flags.c b/src/flags.c @@ -0,0 +1,43 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* 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. * +\******************************************************************************/ + +#include <flags.h> + +static u8_t mpm_flags[MPM_LAST] = {0}; + +/*! + * \brief Set an internal flag + * \param flag Flag number (see enum in flags.h) + * \param val Value to assign + * \note If the flag is greater than MPM_LAST value this function won't do + * anything + */ +void mpm_set_flag(u8_t flag, u8_t val) { + if (flag < MPM_LAST) + mpm_flags[flag] = val; +} + +/*! + * \brief Get an internal flag + * \param flag Flag number (see enum in flags.h) + * \return The flag value + * \note If the value asked by the caller is higher than MPM_LAST, this function + * will raiser an assertion. + */ +u8_t mpm_get_flag(u8_t flag) { + assert(flag < MPM_LAST); + return mpm_flags[flag]; +} diff --git a/tests/main.c b/tests/main.c @@ -1,15 +1,9 @@ #include "test.h" -TEST(oui) { - useless(); - TEST_ASSERT(true, "We'll, something's clearly wrong with your computer."); - return TEST_SUCCESS; -} - int main(void) { int ret; - reg_test("main", oui); + register_flags_test(); ret = test_all(); test_free(); return ret; diff --git a/tests/test.h b/tests/test.h @@ -3,4 +3,6 @@ # include <libmpm.h> +void register_flags_test(void); + #endif /* TEST_H */ diff --git a/tests/tests_flags.c b/tests/tests_flags.c @@ -0,0 +1,19 @@ +#include "test.h" + +TEST(flag_set_base_1) { + mpm_set_flag(MPM_VERBOSE_LEVEL, 2); + TEST_ASSERT((mpm_get_flag(MPM_VERBOSE_LEVEL) == 2), "Value is wrong"); + return TEST_SUCCESS; +} + +TEST(flag_set_base_2) { + mpm_set_flag(150, 8); + TEST_ASSERT((mpm_get_flag(MPM_VERBOSE_LEVEL) == 2), "Value is wrong"); + return TEST_SUCCESS; +} + + +void register_flags_test(void) { + reg_test("flags", flag_set_base_1); + reg_test("flags", flag_set_base_2); +}