This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for error behaviour in internal dev. container functions
Issue #33
- Loading branch information
1 parent
f33580e
commit cd35d4a
Showing
2 changed files
with
92 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* This file is part of cf4ocl (C Framework for OpenCL). | ||
* | ||
* cf4ocl is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* cf4ocl is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with cf4ocl. If not, see <http://www.gnu.org/licenses/>. | ||
* */ | ||
|
||
/** | ||
* @internal | ||
* | ||
* @file | ||
* Tests if errors occur when they should when using cf4ocl. | ||
* | ||
* @author Nuno Fachada | ||
* @date 2019 | ||
* @copyright [GNU General Public License version 3 (GPLv3)](http://www.gnu.org/licenses/gpl.html) | ||
* */ | ||
|
||
#include <cf4ocl2.h> | ||
#include "test.h" | ||
#include "_ccl_abstract_dev_container_wrapper.h" | ||
|
||
/** | ||
* @internal | ||
* | ||
* @brief Used as a mock function for getting devices in a device container | ||
* wrapper. | ||
*/ | ||
static CCLWrapperInfo * mock_get_devices( | ||
CCLDevContainer * devcon, CCLErr ** err) { | ||
|
||
CCL_UNUSED(devcon); | ||
g_set_error(err, CCL_ERROR, CL_INVALID_VALUE, "Mock error"); | ||
return NULL; | ||
} | ||
|
||
/** | ||
* @internal | ||
* | ||
* @brief Tests errors in device container functions. | ||
* */ | ||
static void device_container_test() { | ||
|
||
/* Test variables. */ | ||
CCLDevContainer mock_devcon = { { 0, NULL, NULL, 0 }, 0, NULL }; | ||
CCLDevice * dev; | ||
CCLErr * err = NULL; | ||
|
||
/* Try and get device from mock device container. */ | ||
dev = ccl_dev_container_get_device( | ||
&mock_devcon, mock_get_devices, 0, &err); | ||
|
||
/* Check that dev is NULL */ | ||
g_assert(dev == NULL); | ||
|
||
/* Check the error domain and code, and clear the error. */ | ||
g_assert_error(err, CCL_ERROR, CL_INVALID_VALUE); | ||
g_clear_error(&err); | ||
|
||
/* Confirm that no memory was allocated for wrappers. */ | ||
g_assert(ccl_wrapper_memcheck()); | ||
} | ||
|
||
/** | ||
* @internal | ||
* | ||
* @brief Main function. | ||
* @param[in] argc Number of command line arguments. | ||
* @param[in] argv Command line arguments. | ||
* @return Result of test run. | ||
* */ | ||
int main(int argc, char ** argv) { | ||
|
||
g_test_init(&argc, &argv, NULL); | ||
|
||
g_test_add_func( | ||
"/wrappers/errors/device-container", | ||
device_container_test); | ||
|
||
return g_test_run(); | ||
} |