This class provides APIs to all of the registers of the TI BQ35100 battery gauge, as used on the u-blox C030 primary battery shield.

Dependents:   example-battery-gauge-bq35100

TESTS/unit_tests/default/main.cpp

Committer:
RobMeades
Date:
2017-07-03
Revision:
0:cec745c014b7
Child:
1:ee7cc8d75283

File content as of revision 0:cec745c014b7:

#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
#include "battery_gauge_bq35100.h"

using namespace utest::v1;

// ----------------------------------------------------------------
// COMPILE-TIME MACROS
// ----------------------------------------------------------------

// ----------------------------------------------------------------
// PRIVATE VARIABLES
// ----------------------------------------------------------------

// I2C interface
I2C * gpI2C = new I2C(I2C_SDA, I2C_SCL);

// ----------------------------------------------------------------
// PRIVATE FUNCTIONS
// ----------------------------------------------------------------

// ----------------------------------------------------------------
// TESTS
// ----------------------------------------------------------------

// Test that the BQ35100 battery gauge can be initialised
void test_init() {
    BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
    
    TEST_ASSERT_FALSE(pBatteryGauge->init(NULL));
    TEST_ASSERT(pBatteryGauge->init(gpI2C));
}

// ----------------------------------------------------------------
// TEST ENVIRONMENT
// ----------------------------------------------------------------

// Setup the test environment
utest::v1::status_t test_setup(const size_t number_of_cases) {
    // Setup Greentea, timeout is long enough to run these tests with
    // DEBUG_BQ35100 defined
    GREENTEA_SETUP(480, "default_auto");
    return verbose_test_setup_handler(number_of_cases);
}

// Test cases
Case cases[] = {
    Case("Initialisation", test_init)
};

Specification specification(test_setup, cases);

// ----------------------------------------------------------------
// MAIN
// ----------------------------------------------------------------

// Entry point into the tests
int main() {    
    bool success = false;
    
    if (gpI2C != NULL) {        
        success = !Harness::run(specification);
    } else {
        printf ("Unable to instantiate I2C interface.\n");
    }
    
    return success;
}

// End Of File