-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
a switch to disable logging in optimized builds #1103
- Loading branch information
1 parent
eabaa5d
commit 9bc6157
Showing
6 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright (c) 2018-2019 [Ribose Inc](https://www.ribose.com). | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "rnp_tests.h" | ||
#include "support.h" | ||
|
||
static const char LOGTEST_FILENAME[] = "logtest.log"; | ||
|
||
TEST_F(rnp_tests, test_log_switch) | ||
{ | ||
FILE *stream; | ||
short saved_rnp_log_switch = _rnp_log_switch; | ||
|
||
stream = fopen(LOGTEST_FILENAME, "w"); | ||
assert_non_null(stream); | ||
|
||
// reset _rnp_log_switch manually | ||
_rnp_log_switch = 0; | ||
RNP_LOG_FD(stream, "x"); | ||
fflush(stream); | ||
assert_int_equal(0, ftell(stream)); // nothing was written | ||
|
||
// enable _rnp_log_switch manually | ||
_rnp_log_switch = 1; | ||
RNP_LOG_FD(stream, "x"); | ||
fflush(stream); | ||
assert_int_not_equal(0, ftell(stream)); // something was written | ||
|
||
fclose(stream); | ||
assert_int_equal(0, unlink(LOGTEST_FILENAME)); | ||
|
||
stream = fopen(LOGTEST_FILENAME, "w"); | ||
assert_non_null(stream); | ||
|
||
const char *saved_env = getenv(RNP_LOG_CONSOLE); | ||
if (saved_env) { | ||
assert_int_equal(0, unsetenv(RNP_LOG_CONSOLE)); | ||
} | ||
|
||
// let _rnp_log_switch initialize to 0 from environment variable | ||
_rnp_log_switch = -1; | ||
RNP_LOG_FD(stream, "x"); | ||
fflush(stream); | ||
assert_int_equal(0, ftell(stream)); // nothing was written | ||
|
||
// let _rnp_log_switch initialize to 1 from environment variable | ||
setenv(RNP_LOG_CONSOLE, "1", 1); | ||
_rnp_log_switch = -1; | ||
RNP_LOG_FD(stream, "x"); | ||
fflush(stream); | ||
assert_int_not_equal(0, ftell(stream)); // something was written | ||
|
||
// restore environment variable | ||
if (saved_env) { | ||
assert_int_equal(0, setenv(RNP_LOG_CONSOLE, saved_env, 1)); | ||
} | ||
|
||
// restore _rnp_log_switch | ||
_rnp_log_switch = saved_rnp_log_switch; | ||
|
||
fclose(stream); | ||
assert_int_equal(0, unlink(LOGTEST_FILENAME)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters