<file_sep>cmake_minimum_required(VERSION 3.5)
project(webcam)


add_library(${PROJECT_NAME}
    src/VideoFormat.hpp
    src/VideoFormat.cpp
    )


target_include_directories(${PROJECT_NAME} PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
    )

set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER library)
<file_sep>#pragma once

#include <iosfwd>


namespace cam {

struct VideoFormat {
    unsigned width;
    unsigned height;
    unsigned framerate;
};


bool operator==(const VideoFormat& l, const VideoFormat& r);
bool operator!=(const VideoFormat& l, const VideoFormat& r);

std::ostream& operator<<(std::ostream& oss, const VideoFormat& format);

}<file_sep>#include "VideoFormat.hpp"

#include <iostream>


namespace cam {

bool operator==(const VideoFormat & l, const VideoFormat & r) {
	return l.width == r.width && l.height == r.height && l.framerate == r.framerate;
}


bool operator!=(const VideoFormat & l, const VideoFormat & r) {
	return !(l == r);
}


std::ostream& operator<<(std::ostream& oss, const VideoFormat& format) {
	return oss << format.width << "x" << format.height << "@" << format.framerate << "fps";
}

}<file_sep>cmake_minimum_required(VERSION 3.5)
project(webcam_solution)


add_subdirectory(webcam)


set(BUILD_TESTS on)

if (BUILD_TESTS)
    add_subdirectory(test)
    set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.travis/cmake)
    if (CMAKE_BUILD_TYPE STREQUAL "Coverage")
        include(CodeCoverage)
        setup_target_for_coverage(webcam_coverage webcam_tests coverage)

        SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
        SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
    endif() #CMAKE_BUILD_TYPE STREQUAL "Coverage"
endif()
<file_sep>cmake_minimum_required(VERSION 3.5)
project(webcam_tests)


set(gtest_force_shared_crt ON CACHE BOOL "Always use msvcrt.dll" FORCE)
add_subdirectory(external/googletest)

set_target_properties(gtest PROPERTIES FOLDER gtest)
set_target_properties(gmock PROPERTIES FOLDER gtest)
set_target_properties(gtest_main PROPERTIES FOLDER gtest)
set_target_properties(gmock_main PROPERTIES FOLDER gtest)


add_executable(${PROJECT_NAME}
    src/video_format_tests.cpp
    )


target_link_libraries(${PROJECT_NAME} gtest gmock gtest_main webcam)

set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER tests)
<file_sep>#pragma once

#include <sstream>

#include <gtest/gtest.h>

#include <VideoFormat.hpp>


TEST(VideoFormat, EqualityOperator) {
    cam::VideoFormat a = {1280, 720, 30};
    cam::VideoFormat b = {1280, 720, 30};

    ASSERT_EQ(a, b);
}


TEST(VideoFormat, NotEqualsOperator) {
    cam::VideoFormat c = {1280, 720, 30};
    cam::VideoFormat d = {1280, 1280, 30};

    ASSERT_NE(c, d);
}


TEST(VideoFormat, TestStreamOperator) {
	cam::VideoFormat c = { 1280, 720, 30 };

	std::ostringstream oss;
	oss << c;

	ASSERT_EQ(oss.str(), "1280x720@30fps");
}