Skip to content

Commit

Permalink
Add checkinit which tests if library loads ok and manager initializat…
Browse files Browse the repository at this point in the history
…ion completes; return 0 if everything is ok, 1 for expected errors, linking errors should return 127

Fix Travis clang exclusion

Signed-off-by: Petre Eftime <[email protected]>
  • Loading branch information
Petre Eftime committed Feb 29, 2016
1 parent 1dc1523 commit 2f0c169
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ compiler:
matrix:
exclude:
- compiler: clang
- env: COVERITY_SCAN_BRANCH=1
env: TRAVIS_BRANCH=coverity_scan

env:
global:
Expand Down
6 changes: 6 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ set_target_properties(hellotinyb
PROPERTIES
CXX_STANDARD 11)

add_executable (checkinit checkinit.cpp)
set_target_properties(checkinit
PROPERTIES
CXX_STANDARD 11)

include_directories(${PROJECT_SOURCE_DIR}/api)

target_link_libraries (hellotinyb tinyb)
target_link_libraries (checkinit tinyb)
41 changes: 41 additions & 0 deletions examples/checkinit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Author: Petre Eftime <[email protected]>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <tinyb.hpp>
#include <iostream>

using namespace tinyb;

int main(int argc, char **argv)
{
try {
BluetoothManager *manager = BluetoothManager::get_bluetooth_manager();
} catch(const std::runtime_error& e) {
std::cout << "Expected error: " << e.what() << std::endl;
return 1;
}

std::cout << "Initialization was succesful." << std::endl;
return 0;
}
9 changes: 5 additions & 4 deletions src/BluetoothManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,11 @@ BluetoothManager::BluetoothManager() : event_list()
NULL, /* GCancellable */
&error);

if (gdbus_manager == NULL) {
g_printerr("Error getting object manager client: %s",
error->message);
g_error_free(error);
if (gdbus_manager == nullptr) {
std::string error_str("Error getting object manager client: ");
error_str += error->message;
g_error_free(error);
throw std::runtime_error(error_str);
}

g_thread_new(NULL, init_manager_thread, gdbus_manager);
Expand Down

0 comments on commit 2f0c169

Please sign in to comment.