2024-09-13 01:13:06 -04:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
|
|
2024-09-20 17:43:39 -07:00
|
|
|
#include <string>
|
2024-09-13 01:13:06 -04:00
|
|
|
#include <string_view>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/datalog/FileLogger.hpp"
|
2024-09-13 01:13:06 -04:00
|
|
|
|
2024-10-08 14:55:16 -04:00
|
|
|
TEST(FileLoggerTest, BufferSingleLine) {
|
2024-09-13 01:13:06 -04:00
|
|
|
std::vector<std::string> buf;
|
2025-02-19 23:08:17 -06:00
|
|
|
auto func = wpi::log::FileLogger::Buffer(
|
2024-09-13 01:13:06 -04:00
|
|
|
[&buf](std::string_view line) { buf.emplace_back(line); });
|
|
|
|
|
func("qwertyuiop\n");
|
2024-10-08 14:55:16 -04:00
|
|
|
EXPECT_EQ("qwertyuiop", buf[0]);
|
2024-09-13 01:13:06 -04:00
|
|
|
}
|
|
|
|
|
|
2024-10-08 14:55:16 -04:00
|
|
|
TEST(FileLoggerTest, BufferMultiLine) {
|
2024-09-13 01:13:06 -04:00
|
|
|
std::vector<std::string> buf;
|
2025-02-19 23:08:17 -06:00
|
|
|
auto func = wpi::log::FileLogger::Buffer(
|
2024-09-13 01:13:06 -04:00
|
|
|
[&buf](std::string_view line) { buf.emplace_back(line); });
|
|
|
|
|
func("line 1\nline 2\nline 3\n");
|
2024-10-08 14:55:16 -04:00
|
|
|
EXPECT_EQ("line 1\nline 2\nline 3", buf[0]);
|
2024-09-13 01:13:06 -04:00
|
|
|
}
|
|
|
|
|
|
2024-10-08 14:55:16 -04:00
|
|
|
TEST(FileLoggerTest, BufferPartials) {
|
2024-09-13 01:13:06 -04:00
|
|
|
std::vector<std::string> buf;
|
2025-02-19 23:08:17 -06:00
|
|
|
auto func = wpi::log::FileLogger::Buffer(
|
2024-09-13 01:13:06 -04:00
|
|
|
[&buf](std::string_view line) { buf.emplace_back(line); });
|
|
|
|
|
func("part 1");
|
|
|
|
|
func("part 2\npart 3");
|
2024-10-08 14:55:16 -04:00
|
|
|
EXPECT_EQ("part 1part 2", buf[0]);
|
2024-09-13 01:13:06 -04:00
|
|
|
func("\n");
|
2024-10-08 14:55:16 -04:00
|
|
|
EXPECT_EQ("part 3", buf[1]);
|
2024-09-13 01:13:06 -04:00
|
|
|
}
|
|
|
|
|
|
2024-10-08 14:55:16 -04:00
|
|
|
TEST(FileLoggerTest, BufferMultiplePartials) {
|
2024-09-13 01:13:06 -04:00
|
|
|
std::vector<std::string> buf;
|
2025-02-19 23:08:17 -06:00
|
|
|
auto func = wpi::log::FileLogger::Buffer(
|
2024-09-13 01:13:06 -04:00
|
|
|
[&buf](std::string_view line) { buf.emplace_back(line); });
|
|
|
|
|
func("part 1");
|
|
|
|
|
func("part 2");
|
|
|
|
|
func("part 3");
|
|
|
|
|
func("part 4\n");
|
2024-10-08 14:55:16 -04:00
|
|
|
EXPECT_EQ("part 1part 2part 3part 4", buf[0]);
|
|
|
|
|
}
|
|
|
|
|
TEST(FileLoggerTest, BufferMultipleMultiLinePartials) {
|
|
|
|
|
std::vector<std::string> buf;
|
2025-02-19 23:08:17 -06:00
|
|
|
auto func = wpi::log::FileLogger::Buffer(
|
2024-10-08 14:55:16 -04:00
|
|
|
[&buf](std::string_view line) { buf.emplace_back(line); });
|
|
|
|
|
func("part 1");
|
|
|
|
|
func("part 2\npart 3");
|
|
|
|
|
func("part 4\n");
|
|
|
|
|
EXPECT_EQ("part 1part 2", buf[0]);
|
|
|
|
|
EXPECT_EQ("part 3part 4", buf[1]);
|
2024-09-13 01:13:06 -04:00
|
|
|
}
|