Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SW_Output.c comptabile with c++ to include in unit testing code #85

Closed
Tracked by #378
dschlaep opened this issue Nov 22, 2017 · 2 comments · Fixed by #391
Closed
Tracked by #378

Make SW_Output.c comptabile with c++ to include in unit testing code #85

dschlaep opened this issue Nov 22, 2017 · 2 comments · Fixed by #391

Comments

@dschlaep
Copy link
Member

We still cannot include SW_Output.c when unit testing because

  • "error: cannot increment expression of enum type" (e.g., OutKey, OutPeriod)
  • "error: assigning to 'OutKey' from incompatible type 'int'", and similar cases

--> once these are fixed, we can update the makefile and replace/delete sources_tests and objects_tests with sources and objects respectively

@dschlaep dschlaep added the bug label Nov 22, 2017
@dschlaep dschlaep added this to the Code testing milestone Nov 22, 2017
@dschlaep
Copy link
Member Author

arising from issue #82

@dschlaep
Copy link
Member Author

A solution may be to implement a similar change for OutKey, OutPeriod, etc. as what I did to typedef enum {...} Months; in commmit 83a6429?

dschlaep added a commit that referenced this issue Nov 22, 2017
- now close #82

We still cannot include SW_Output.c when unit testing:
* "error: cannot increment expression of enum type" (e.g., OutKey,
OutPeriod)
* "error: assigning to 'OutKey' from incompatible type 'int'", and
similar cases

--> for now, exclude SW_Output.c (see new issue #85), work on fixing
the errors under c++ and then

- address c++ compile "warning: ISO C++11 does not allow conversion
from string literal to 'char *'"
--> don't define such variables as "char *" but instead as "char const
*" (see
https://stackoverflow.com/questions/20944784/why-is-conversion-from-stri
ng-constant-to-char-valid-in-c-but-invalid-in-c#20944858)
dschlaep added a commit that referenced this issue Nov 27, 2017
- until we resolve issue #85, we need the functions from 'SW_Output.c'
defined alternatively
- SW_Output_mock.c provides mock definitions for these functions
- compiling unit tests with 'SW_Output_mock.c' allows us to include
'SW_Output.h' in our unit test files

- note: I attempted to eliminate compile warnings (hence some weird
code snippets), but one warning remains
> SW_Output_mock.c:204:13: warning: unused function '_echo_outputs'
[-Wunused-function]
static void _echo_outputs(void)
dschlaep added a commit that referenced this issue Dec 5, 2017
- until we resolve issue #85, we need the functions from 'SW_Output.c'
defined alternatively
- SW_Output_mock.c provides mock definitions for these functions
- compiling unit tests with 'SW_Output_mock.c' allows us to include
'SW_Output.h' in our unit test files

- note: I attempted to eliminate compile warnings (hence some weird
code snippets), but one warning remains
> SW_Output_mock.c:204:13: warning: unused function '_echo_outputs'
[-Wunused-function]
static void _echo_outputs(void)
dschlaep added a commit that referenced this issue Feb 8, 2024
- close #85 (issue "Make SW_Output.c compatible with c++ to include in unit testing code")

-> update "makefile" -- include output code in test program

-> delete "SW_Output_mock.c" -- no longer needed

-> fix test variable `template_SW_OutputPtrs` which must be an array of length `SW_OUTNKEYS` -- see `SW_OutputPtrs` of `main()`

-> new `SW_OUT_close_files()` and `SW_OUT_create_files()` in module "SW_Output" (which call existing functions that are renamed to `SW_OUT_close_textfiles()` and `SW_OUT_create_textfiles()` from "SW_Output_outtext")

-> make sure `free()` is only called if pointer is not null

-> `setup_testGlobalSoilwatTemplate()` now calls `SW_OUT_set_ncol()` and `SW_OUT_set_colnames()` -- as `main()` has been doing

-> new `SW_GENOUT_init_ptrs()` (split out from `SW_OUT_init_ptrs()` which now only operates on `SW_OUTPUT`)

-> new `SW_GENOUT_deepCopy()` which is called by `SW_ALL_deepCopy()`

-> new `SW_OUT_construct_outarray()` which is renamed from `setGlobalSTEPWAT2_OutputVariables()` and now made available if SW_OUTARRAY

-> tests compile all code as C++ (instead of C) which leads to several friction points:

* errors due to 'ForEachOutKey' --> define `k` as int and coerce to 'OutKey' as needed
** error: assigning to 'OutKey' from incompatible type 'int': ```ForEachOutKey(k) ...```
** error: cannot increment expression of enum type 'OutKey': ```#define ForEachOutKey(k) for((k)=eSW_NoKey+1; (k)<eSW_LastKey; (k)++)```

* error: assigning to 'Bool' from incompatible type 'bool' --> coerce to 'Bool' (after correctly setting parentheses)

* warning: ISO C++11 does not allow conversion from string literal to 'char *' --> coerce to 'char *'

* error: variable length arrays are a C99 feature [-Werror,-Wvla-extension] --> dynamically allocate and de-allocate memory in `_create_csv_headers()` and `write_headers_to_csv()`
@dschlaep dschlaep modified the milestones: Code testing, Release v8.0.0 Feb 8, 2024
dschlaep added a commit that referenced this issue Feb 8, 2024
Feature include output code in tests

- close #85
@dschlaep dschlaep self-assigned this Jun 5, 2024
@dschlaep dschlaep closed this as completed Jun 5, 2024
@dschlaep dschlaep linked a pull request Jun 6, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant