C wrapper for DataLog class
A pure C wrapper for the DataLog class was created. Since templates are not supported in C, the InsertCell method of the DataLog class must be wrapped using one wrapper function for each data type. So far, the wrapper includes int, float, double, Word32, UWord32, and Word64. Unittests were created for the wrapper. A separate helper file was included in the tests. This helper file was implemented as a C file, in order to actually test the C linkage of the wrapper. The unittests for DataLog were cloned to make versions that do the same things but through the C wrapper interface. Restructured the code so that the log file verification was not duplicated. Review URL: http://webrtc-codereview.appspot.com/195003 git-svn-id: http://webrtc.googlecode.com/svn/trunk@715 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
6364d128a1
commit
d855bd4d6f
88
src/system_wrappers/interface/data_log_c.h
Normal file
88
src/system_wrappers/interface/data_log_c.h
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is a pure C wrapper of the DataLog class. The functions are directly
|
||||
* mapped here except for InsertCell as C does not support templates.
|
||||
* See data_log.h for a description of the functions.
|
||||
*/
|
||||
|
||||
#ifndef SRC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_C_H_
|
||||
#define SRC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_C_H_
|
||||
|
||||
#include <stddef.h> /* size_t */
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* All char* parameters in this file are expected to be null-terminated
|
||||
* character sequences.
|
||||
*/
|
||||
int WebRtcDataLog_CreateLog();
|
||||
void WebRtcDataLog_ReturnLog();
|
||||
char* WebRtcDataLog_Combine(char* combined_name, size_t combined_len,
|
||||
const char* table_name, int table_id);
|
||||
int WebRtcDataLog_AddTable(const char* table_name);
|
||||
int WebRtcDataLog_AddColumn(const char* table_name, const char* column_name,
|
||||
int multi_value_length);
|
||||
|
||||
int WebRtcDataLog_InsertCell_int(const char* table_name,
|
||||
const char* column_name,
|
||||
int value);
|
||||
int WebRtcDataLog_InsertArray_int(const char* table_name,
|
||||
const char* column_name,
|
||||
const int* values,
|
||||
int length);
|
||||
int WebRtcDataLog_InsertCell_float(const char* table_name,
|
||||
const char* column_name,
|
||||
float value);
|
||||
int WebRtcDataLog_InsertArray_float(const char* table_name,
|
||||
const char* column_name,
|
||||
const float* values,
|
||||
int length);
|
||||
int WebRtcDataLog_InsertCell_double(const char* table_name,
|
||||
const char* column_name,
|
||||
double value);
|
||||
int WebRtcDataLog_InsertArray_double(const char* table_name,
|
||||
const char* column_name,
|
||||
const double* values,
|
||||
int length);
|
||||
int WebRtcDataLog_InsertCell_int32(const char* table_name,
|
||||
const char* column_name,
|
||||
int32_t value);
|
||||
int WebRtcDataLog_InsertArray_int32(const char* table_name,
|
||||
const char* column_name,
|
||||
const int32_t* values,
|
||||
int length);
|
||||
int WebRtcDataLog_InsertCell_uint32(const char* table_name,
|
||||
const char* column_name,
|
||||
uint32_t value);
|
||||
int WebRtcDataLog_InsertArray_uint32(const char* table_name,
|
||||
const char* column_name,
|
||||
const uint32_t* values,
|
||||
int length);
|
||||
int WebRtcDataLog_InsertCell_int64(const char* table_name,
|
||||
const char* column_name,
|
||||
int64_t value);
|
||||
int WebRtcDataLog_InsertArray_int64(const char* table_name,
|
||||
const char* column_name,
|
||||
const int64_t* values,
|
||||
int length);
|
||||
|
||||
int WebRtcDataLog_NextRow(const char* table_name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* end of extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* SRC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_C_H_ */
|
145
src/system_wrappers/source/data_log_c.cc
Normal file
145
src/system_wrappers/source/data_log_c.cc
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the pure C wrapper of the DataLog class.
|
||||
*/
|
||||
|
||||
#include "system_wrappers/interface/data_log_c.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "system_wrappers/interface/data_log.h"
|
||||
|
||||
extern "C" int WebRtcDataLog_CreateLog() {
|
||||
return webrtc::DataLog::CreateLog();
|
||||
}
|
||||
|
||||
extern "C" void WebRtcDataLog_ReturnLog() {
|
||||
return webrtc::DataLog::ReturnLog();
|
||||
}
|
||||
|
||||
extern "C" char* WebRtcDataLog_Combine(char* combined_name, size_t combined_len,
|
||||
const char* table_name, int table_id) {
|
||||
if (!table_name) return NULL;
|
||||
std::string combined = webrtc::DataLog::Combine(table_name, table_id);
|
||||
if (combined.size() >= combined_len) return NULL;
|
||||
std::copy(combined.begin(), combined.end(), combined_name);
|
||||
combined_name[combined.size()] = '\0';
|
||||
return combined_name;
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_AddTable(const char* table_name) {
|
||||
if (!table_name) return -1;
|
||||
return webrtc::DataLog::AddTable(table_name);
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_AddColumn(const char* table_name,
|
||||
const char* column_name,
|
||||
int multi_value_length) {
|
||||
if (!table_name || !column_name) return -1;
|
||||
return webrtc::DataLog::AddColumn(table_name, column_name,
|
||||
multi_value_length);
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_InsertCell_int(const char* table_name,
|
||||
const char* column_name,
|
||||
int value) {
|
||||
if (!table_name || !column_name) return -1;
|
||||
return webrtc::DataLog::InsertCell(table_name, column_name, value);
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_InsertArray_int(const char* table_name,
|
||||
const char* column_name,
|
||||
const int* values,
|
||||
int length) {
|
||||
if (!table_name || !column_name) return -1;
|
||||
return webrtc::DataLog::InsertCell(table_name, column_name, values, length);
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_InsertCell_float(const char* table_name,
|
||||
const char* column_name,
|
||||
float value) {
|
||||
if (!table_name || !column_name) return -1;
|
||||
return webrtc::DataLog::InsertCell(table_name, column_name, value);
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_InsertArray_float(const char* table_name,
|
||||
const char* column_name,
|
||||
const float* values,
|
||||
int length) {
|
||||
if (!table_name || !column_name) return -1;
|
||||
return webrtc::DataLog::InsertCell(table_name, column_name, values, length);
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_InsertCell_double(const char* table_name,
|
||||
const char* column_name,
|
||||
double value) {
|
||||
if (!table_name || !column_name) return -1;
|
||||
return webrtc::DataLog::InsertCell(table_name, column_name, value);
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_InsertArray_double(const char* table_name,
|
||||
const char* column_name,
|
||||
const double* values,
|
||||
int length) {
|
||||
if (!table_name || !column_name) return -1;
|
||||
return webrtc::DataLog::InsertCell(table_name, column_name, values, length);
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_InsertCell_int32(const char* table_name,
|
||||
const char* column_name,
|
||||
int32_t value) {
|
||||
if (!table_name || !column_name) return -1;
|
||||
return webrtc::DataLog::InsertCell(table_name, column_name, value);
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_InsertArray_int32(const char* table_name,
|
||||
const char* column_name,
|
||||
const int32_t* values,
|
||||
int length) {
|
||||
if (!table_name || !column_name) return -1;
|
||||
return webrtc::DataLog::InsertCell(table_name, column_name, values, length);
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_InsertCell_uint32(const char* table_name,
|
||||
const char* column_name,
|
||||
uint32_t value) {
|
||||
if (!table_name || !column_name) return -1;
|
||||
return webrtc::DataLog::InsertCell(table_name, column_name, value);
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_InsertArray_uint32(const char* table_name,
|
||||
const char* column_name,
|
||||
const uint32_t* values,
|
||||
int length) {
|
||||
if (!table_name || !column_name) return -1;
|
||||
return webrtc::DataLog::InsertCell(table_name, column_name, values, length);
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_InsertCell_int64(const char* table_name,
|
||||
const char* column_name,
|
||||
int64_t value) {
|
||||
if (!table_name || !column_name) return -1;
|
||||
return webrtc::DataLog::InsertCell(table_name, column_name, value);
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_InsertArray_int64(const char* table_name,
|
||||
const char* column_name,
|
||||
const int64_t* values,
|
||||
int length) {
|
||||
if (!table_name || !column_name) return -1;
|
||||
return webrtc::DataLog::InsertCell(table_name, column_name, values, length);
|
||||
}
|
||||
|
||||
extern "C" int WebRtcDataLog_NextRow(const char* table_name) {
|
||||
if (!table_name) return -1;
|
||||
return webrtc::DataLog::NextRow(table_name);
|
||||
}
|
117
src/system_wrappers/source/data_log_c_helpers_unittest.c
Normal file
117
src/system_wrappers/source/data_log_c_helpers_unittest.c
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "system_wrappers/source/data_log_c_helpers_unittest.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "system_wrappers/interface/data_log_c.h"
|
||||
|
||||
enum { kTestArrayLen = 4 };
|
||||
static const char kTableName[] = "c_wrapper_table";
|
||||
static const char kColumnName1[] = "Scalar";
|
||||
static const char kColumnName2[] = "Vector";
|
||||
|
||||
int WebRtcDataLogCHelper_TestCreateLog() {
|
||||
return WebRtcDataLog_CreateLog();
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestReturnLog() {
|
||||
WebRtcDataLog_ReturnLog();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestCombine() {
|
||||
const int kOutLen = strlen(kTableName) + 4; /* Room for "_17" + '\0' */
|
||||
char combined_name[kOutLen];
|
||||
char* out_ptr = WebRtcDataLog_Combine(combined_name, kOutLen, kTableName, 17);
|
||||
if (!out_ptr) return -1;
|
||||
if (strcmp(combined_name, "c_wrapper_table_17") != 0) return -2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestAddTable() {
|
||||
return WebRtcDataLog_AddTable(kTableName);
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestAddColumn() {
|
||||
if (WebRtcDataLog_AddColumn(kTableName, kColumnName1, 1) != 0) {
|
||||
return -1;
|
||||
}
|
||||
if (WebRtcDataLog_AddColumn(kTableName, kColumnName2, kTestArrayLen) != 0) {
|
||||
return -2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestNextRow() {
|
||||
return WebRtcDataLog_NextRow(kTableName);
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertCell_int() {
|
||||
return WebRtcDataLog_InsertCell_int(kTableName, kColumnName1, 17);
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertArray_int() {
|
||||
int values[kTestArrayLen] = {1, 2, 3, 4};
|
||||
return WebRtcDataLog_InsertArray_int(kTableName, kColumnName2, values,
|
||||
kTestArrayLen);
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertCell_float() {
|
||||
return WebRtcDataLog_InsertCell_float(kTableName, kColumnName1, 17.0f);
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertArray_float() {
|
||||
float values[kTestArrayLen] = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
return WebRtcDataLog_InsertArray_float(kTableName, kColumnName2, values,
|
||||
kTestArrayLen);
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertCell_double() {
|
||||
return WebRtcDataLog_InsertCell_int(kTableName, kColumnName1, 17.0);
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertArray_double() {
|
||||
double values[kTestArrayLen] = {1.0, 2.0, 3.0, 4.0};
|
||||
return WebRtcDataLog_InsertArray_double(kTableName, kColumnName2, values,
|
||||
kTestArrayLen);
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertCell_int32() {
|
||||
return WebRtcDataLog_InsertCell_int32(kTableName, kColumnName1, 17);
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertArray_int32() {
|
||||
int32_t values[kTestArrayLen] = {1, 2, 3, 4};
|
||||
return WebRtcDataLog_InsertArray_int32(kTableName, kColumnName2, values,
|
||||
kTestArrayLen);
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertCell_uint32() {
|
||||
return WebRtcDataLog_InsertCell_uint32(kTableName, kColumnName1, 17);
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertArray_uint32() {
|
||||
uint32_t values[kTestArrayLen] = {1, 2, 3, 4};
|
||||
return WebRtcDataLog_InsertArray_uint32(kTableName, kColumnName2, values,
|
||||
kTestArrayLen);
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertCell_int64() {
|
||||
return WebRtcDataLog_InsertCell_int64(kTableName, kColumnName1, 17);
|
||||
}
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertArray_int64() {
|
||||
int64_t values[kTestArrayLen] = {1, 2, 3, 4};
|
||||
return WebRtcDataLog_InsertArray_int64(kTableName, kColumnName2, values,
|
||||
kTestArrayLen);
|
||||
}
|
58
src/system_wrappers/source/data_log_c_helpers_unittest.h
Normal file
58
src/system_wrappers/source/data_log_c_helpers_unittest.h
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef SRC_SYSTEM_WRAPPERS_SOURCE_DATA_LOG_C_HELPERS_UNITTEST_H_
|
||||
#define SRC_SYSTEM_WRAPPERS_SOURCE_DATA_LOG_C_HELPERS_UNITTEST_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int WebRtcDataLogCHelper_TestCreateLog();
|
||||
|
||||
int WebRtcDataLogCHelper_TestReturnLog();
|
||||
|
||||
int WebRtcDataLogCHelper_TestCombine();
|
||||
|
||||
int WebRtcDataLogCHelper_TestAddTable();
|
||||
|
||||
int WebRtcDataLogCHelper_TestAddColumn();
|
||||
|
||||
int WebRtcDataLogCHelper_TestNextRow();
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertCell_int();
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertArray_int();
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertCell_float();
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertArray_float();
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertCell_double();
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertArray_double();
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertCell_int32();
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertArray_int32();
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertCell_uint32();
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertArray_uint32();
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertCell_int64();
|
||||
|
||||
int WebRtcDataLogCHelper_TestInsertArray_int64();
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // end of extern "C"
|
||||
#endif
|
||||
|
||||
#endif // SRC_SYSTEM_WRAPPERS_SOURCE_DATA_LOG_C_HELPERS_UNITTEST_H_
|
@ -11,7 +11,9 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "data_log.h"
|
||||
#include "system_wrappers/interface/data_log.h"
|
||||
#include "system_wrappers/interface/data_log_c.h"
|
||||
#include "system_wrappers/source/data_log_c_helpers_unittest.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using ::webrtc::DataLog;
|
||||
@ -272,3 +274,32 @@ TEST(TestDataLog, VerifyMultipleTables) {
|
||||
fclose(table);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TestDataLogCWrapper, VerifyCWrapper) {
|
||||
// Simply call all C wrapper log functions through the C helper unittests.
|
||||
// Main purpose is to make sure that the linkage is correct.
|
||||
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestCreateLog());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestCombine());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestAddTable());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestAddColumn());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_int());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_int());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_float());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_float());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_double());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_double());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_int32());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_int32());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_uint32());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_uint32());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_int64());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_int64());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow());
|
||||
EXPECT_EQ(0, WebRtcDataLogCHelper_TestReturnLog());
|
||||
}
|
||||
|
@ -33,6 +33,7 @@
|
||||
'../interface/cpu_features_wrapper.h',
|
||||
'../interface/critical_section_wrapper.h',
|
||||
'../interface/data_log.h',
|
||||
'../interface/data_log_c.h',
|
||||
'../interface/data_log_impl.h',
|
||||
'../interface/event_wrapper.h',
|
||||
'../interface/file_wrapper.h',
|
||||
@ -63,6 +64,7 @@
|
||||
'critical_section.cc',
|
||||
'critical_section_posix.h',
|
||||
'critical_section_windows.h',
|
||||
'data_log_c.cc',
|
||||
'event.cc',
|
||||
'event_posix.h',
|
||||
'event_windows.h',
|
||||
|
@ -26,6 +26,8 @@
|
||||
'list_unittest.cc',
|
||||
'map_unittest.cc',
|
||||
'data_log_helpers_unittest.cc',
|
||||
'data_log_c_helpers_unittest.c',
|
||||
'data_log_c_helpers_unittest.h',
|
||||
],
|
||||
'conditions': [
|
||||
['enable_data_logging==1', {
|
||||
|
Loading…
x
Reference in New Issue
Block a user