LcamDev: Add baked in camera profiles; use new test supports
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <catalogHelpers.h>
|
||||
#include <selectorParse.h>
|
||||
#include <selectorResolve.h>
|
||||
#include <stdexcept>
|
||||
@@ -8,6 +9,8 @@
|
||||
namespace lcamera_dev {
|
||||
namespace {
|
||||
|
||||
constexpr const char *dellLaptopMachineTag = "dell-laptop";
|
||||
|
||||
static CameraIdentityRecord makeRecord(
|
||||
const std::string& id,
|
||||
const std::string& model = "",
|
||||
@@ -20,7 +23,7 @@ static CameraIdentityRecord makeRecord(
|
||||
return record;
|
||||
}
|
||||
|
||||
static std::vector<CameraIdentityRecord> sampleRecords()
|
||||
static std::vector<CameraIdentityRecord> syntheticAmbiguityRecords()
|
||||
{
|
||||
return {
|
||||
makeRecord("/base/cam0", "imx219", "back"),
|
||||
@@ -31,18 +34,68 @@ static std::vector<CameraIdentityRecord> sampleRecords()
|
||||
|
||||
TEST(FormatCameraListForDiagnosticsTest, ListsIndexedCameras)
|
||||
{
|
||||
const std::vector<CameraIdentityRecord> records = sampleRecords();
|
||||
const std::vector<CameraIdentityRecord> records =
|
||||
tests::bakedProfilesAsRecords(dellLaptopMachineTag);
|
||||
const std::string text = formatCameraListForDiagnostics(records);
|
||||
|
||||
EXPECT_NE(text.find("Known cameras:"), std::string::npos);
|
||||
EXPECT_NE(text.find("[0] id=/base/cam0"), std::string::npos);
|
||||
EXPECT_NE(text.find("model=imx219"), std::string::npos);
|
||||
EXPECT_NE(text.find("HDMI USB Camera"), std::string::npos);
|
||||
EXPECT_NE(text.find("location=external"), std::string::npos);
|
||||
EXPECT_NE(text.find("Integrated_Webcam_HD"), std::string::npos);
|
||||
EXPECT_NE(text.find("location=front"), std::string::npos);
|
||||
}
|
||||
|
||||
TEST(ResolveSelectorAgainstRecordsTest, BakedUsbHdmiCameraMatchesExampleSelector)
|
||||
{
|
||||
const std::vector<CameraIdentityRecord> records =
|
||||
tests::bakedProfilesAsRecords(dellLaptopMachineTag);
|
||||
const std::vector<SelectorCriterion> criteria =
|
||||
parseDeviceSelector("model-substr:HDMI;location:EXTERNAL");
|
||||
|
||||
const CameraIdentityRecord resolved =
|
||||
resolveSelectorAgainstRecords(criteria, records);
|
||||
|
||||
EXPECT_EQ(
|
||||
resolved.id,
|
||||
"\\_SB_.PCI0.XHC_.RHUB.HS01-1:1.0-32e4:9415");
|
||||
EXPECT_EQ(resolved.locationLabel, "external");
|
||||
}
|
||||
|
||||
TEST(ResolveSelectorAgainstRecordsTest, BakedIntegratedWebcamMatchesExampleSelector)
|
||||
{
|
||||
const std::vector<CameraIdentityRecord> records =
|
||||
tests::bakedProfilesAsRecords(dellLaptopMachineTag);
|
||||
const std::vector<SelectorCriterion> criteria =
|
||||
parseDeviceSelector("model-substr:Integrated;location:front");
|
||||
|
||||
const CameraIdentityRecord resolved =
|
||||
resolveSelectorAgainstRecords(criteria, records);
|
||||
|
||||
EXPECT_EQ(
|
||||
resolved.id,
|
||||
"\\_SB_.PCI0.XHC_.RHUB.HS04-4:1.0-1bcf:2b8a");
|
||||
EXPECT_EQ(resolved.locationLabel, "front");
|
||||
}
|
||||
|
||||
TEST(ResolveSelectorAgainstRecordsTest, BakedUsbCameraMatchesLibcameraId)
|
||||
{
|
||||
const std::vector<CameraIdentityRecord> records =
|
||||
tests::bakedProfilesAsRecords(dellLaptopMachineTag);
|
||||
const std::vector<SelectorCriterion> criteria =
|
||||
parseDeviceSelector(
|
||||
"lcamera-id:\\_SB_.PCI0.XHC_.RHUB.HS01-1:1.0-32e4:9415");
|
||||
|
||||
const CameraIdentityRecord resolved =
|
||||
resolveSelectorAgainstRecords(criteria, records);
|
||||
|
||||
EXPECT_EQ(
|
||||
resolved.id,
|
||||
"\\_SB_.PCI0.XHC_.RHUB.HS01-1:1.0-32e4:9415");
|
||||
}
|
||||
|
||||
TEST(ResolveSelectorAgainstRecordsTest, MatchesLibcameraId)
|
||||
{
|
||||
const std::vector<CameraIdentityRecord> records = sampleRecords();
|
||||
const std::vector<CameraIdentityRecord> records = syntheticAmbiguityRecords();
|
||||
const std::vector<SelectorCriterion> criteria =
|
||||
parseDeviceSelector("lcamera-id:/base/cam1");
|
||||
|
||||
@@ -54,7 +107,7 @@ TEST(ResolveSelectorAgainstRecordsTest, MatchesLibcameraId)
|
||||
|
||||
TEST(ResolveSelectorAgainstRecordsTest, MatchesModelSubstrAndLocation)
|
||||
{
|
||||
const std::vector<CameraIdentityRecord> records = sampleRecords();
|
||||
const std::vector<CameraIdentityRecord> records = syntheticAmbiguityRecords();
|
||||
const std::vector<SelectorCriterion> criteria =
|
||||
parseDeviceSelector("model-substr:Logitech;location:EXTERNAL");
|
||||
|
||||
@@ -66,7 +119,7 @@ TEST(ResolveSelectorAgainstRecordsTest, MatchesModelSubstrAndLocation)
|
||||
|
||||
TEST(ResolveSelectorAgainstRecordsTest, IndexSelectsNthCamera)
|
||||
{
|
||||
const std::vector<CameraIdentityRecord> records = sampleRecords();
|
||||
const std::vector<CameraIdentityRecord> records = syntheticAmbiguityRecords();
|
||||
const std::vector<SelectorCriterion> criteria =
|
||||
parseDeviceSelector("index:2");
|
||||
|
||||
@@ -78,7 +131,7 @@ TEST(ResolveSelectorAgainstRecordsTest, IndexSelectsNthCamera)
|
||||
|
||||
TEST(ResolveSelectorAgainstRecordsTest, IndexCombinedWithModel)
|
||||
{
|
||||
const std::vector<CameraIdentityRecord> records = sampleRecords();
|
||||
const std::vector<CameraIdentityRecord> records = syntheticAmbiguityRecords();
|
||||
const std::vector<SelectorCriterion> criteria =
|
||||
parseDeviceSelector("index:0;model:imx219");
|
||||
|
||||
@@ -90,7 +143,7 @@ TEST(ResolveSelectorAgainstRecordsTest, IndexCombinedWithModel)
|
||||
|
||||
TEST(ResolveSelectorAgainstRecordsTest, ZeroMatchesThrowsWithDiagnostics)
|
||||
{
|
||||
const std::vector<CameraIdentityRecord> records = sampleRecords();
|
||||
const std::vector<CameraIdentityRecord> records = syntheticAmbiguityRecords();
|
||||
const std::vector<SelectorCriterion> criteria =
|
||||
parseDeviceSelector("model:does-not-exist");
|
||||
|
||||
@@ -111,7 +164,7 @@ TEST(ResolveSelectorAgainstRecordsTest, ZeroMatchesThrowsWithDiagnostics)
|
||||
|
||||
TEST(ResolveSelectorAgainstRecordsTest, AmbiguousSelectorThrows)
|
||||
{
|
||||
const std::vector<CameraIdentityRecord> records = sampleRecords();
|
||||
const std::vector<CameraIdentityRecord> records = syntheticAmbiguityRecords();
|
||||
const std::vector<SelectorCriterion> criteria =
|
||||
parseDeviceSelector("model:imx219");
|
||||
|
||||
@@ -122,7 +175,7 @@ TEST(ResolveSelectorAgainstRecordsTest, AmbiguousSelectorThrows)
|
||||
|
||||
TEST(ResolveSelectorAgainstRecordsTest, IndexOutOfRangeThrows)
|
||||
{
|
||||
const std::vector<CameraIdentityRecord> records = sampleRecords();
|
||||
const std::vector<CameraIdentityRecord> records = syntheticAmbiguityRecords();
|
||||
const std::vector<SelectorCriterion> criteria =
|
||||
parseDeviceSelector("index:9");
|
||||
|
||||
@@ -133,7 +186,7 @@ TEST(ResolveSelectorAgainstRecordsTest, IndexOutOfRangeThrows)
|
||||
|
||||
TEST(ResolveSelectorAgainstRecordsTest, IndexConflictsWithOtherClauses)
|
||||
{
|
||||
const std::vector<CameraIdentityRecord> records = sampleRecords();
|
||||
const std::vector<CameraIdentityRecord> records = syntheticAmbiguityRecords();
|
||||
const std::vector<SelectorCriterion> criteria =
|
||||
parseDeviceSelector("index:0;location:front");
|
||||
|
||||
@@ -144,7 +197,7 @@ TEST(ResolveSelectorAgainstRecordsTest, IndexConflictsWithOtherClauses)
|
||||
|
||||
TEST(ResolveSelectorAgainstRecordsTest, InvalidIndexValueThrows)
|
||||
{
|
||||
const std::vector<CameraIdentityRecord> records = sampleRecords();
|
||||
const std::vector<CameraIdentityRecord> records = syntheticAmbiguityRecords();
|
||||
const std::vector<SelectorCriterion> criteria =
|
||||
parseDeviceSelector("index:not-a-number");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user