1 /* 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "system_wrappers/interface/data_log.h" 12 13 #include <cstdio> 14 15 #include "gtest/gtest.h" 16 17 using ::webrtc::DataLog; 18 19 const char* kDataLogFileName = "table_1.txt"; 20 21 void PerformLogging(std::string table_name) { 22 // Simulate normal DataTable logging behavior using this table name. 23 ASSERT_EQ(0, DataLog::AddTable(table_name)); 24 ASSERT_EQ(0, DataLog::AddColumn(table_name, "test", 1)); 25 for (int i = 0; i < 10; ++i) { 26 // TODO(kjellander): Check InsertCell result when the DataLog dummy is 27 // fixed. 28 DataLog::InsertCell(table_name, "test", static_cast<double>(i)); 29 ASSERT_EQ(0, DataLog::NextRow(table_name)); 30 } 31 } 32 33 // Simple test to verify DataLog is still working when the GYP variable 34 // enable_data_logging==0 (the default case). 35 TEST(TestDataLogDisabled, VerifyLoggingWorks) { 36 ASSERT_EQ(0, DataLog::CreateLog()); 37 // Generate a table_name name and assure it's an empty string 38 // (dummy behavior). 39 std::string table_name = DataLog::Combine("table", 1); 40 ASSERT_EQ("", table_name); 41 PerformLogging(table_name); 42 DataLog::ReturnLog(); 43 } 44 45 TEST(TestDataLogDisabled, EnsureNoFileIsWritten) { 46 // Remove any previous data files on disk: 47 std::remove(kDataLogFileName); 48 ASSERT_EQ(0, DataLog::CreateLog()); 49 // Don't use the table name we would get from Combine on a disabled DataLog. 50 // Use "table_1" instead (which is what an enabled DataLog would give us). 51 PerformLogging("table_1"); 52 DataLog::ReturnLog(); 53 // Verify no data log file have been written: 54 ASSERT_EQ(NULL, fopen(kDataLogFileName, "r")); 55 } 56