1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
// TapTempo, a command line tap tempo.
// Copyright (C) 2017 Francois Mazen
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "../src/options.h"
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#define DEFAULT_SAMPLE_SIZE 5
#define DEFAULT_RESET_TIME 5
#define DEFAULT_PRECISION 0
#define MAX_PRECISION 5
TEST_CASE("Invalid args should returns default options")
{
Options options = Options::createFromArgs(0, 0);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Zero args should returns default options")
{
char programName[] = "taptempo";
char* argPointer = &programName[0];
Options options = Options::createFromArgs(1, &argPointer);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Help switch should exit")
{
char programName[] = "taptempo";
char helpSwitch[] = "--help";
char* arguments[2] = {programName, helpSwitch};
Options options = Options::createFromArgs(2, arguments);
REQUIRE(options.getShouldExit() == true);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Short help switch should exit")
{
char programName[] = "taptempo";
char helpSwitch[] = "-h";
char* arguments[2] = {programName, helpSwitch};
Options options = Options::createFromArgs(2, arguments);
REQUIRE(options.getShouldExit() == true);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Version switch should exit")
{
char programName[] = "taptempo";
char versionSwitch[] = "--version";
char* arguments[2] = {programName, versionSwitch};
Options options = Options::createFromArgs(2, arguments);
REQUIRE(options.getShouldExit() == true);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Short version switch should exit")
{
char programName[] = "taptempo";
char versionSwitch[] = "-v";
char* arguments[2] = {programName, versionSwitch};
Options options = Options::createFromArgs(2, arguments);
REQUIRE(options.getShouldExit() == true);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Precision switch should return the right value")
{
char programName[] = "taptempo";
char precisionSwitch[] = "--precision";
char precisionValue[] = "2";
char* arguments[3] = {programName, precisionSwitch, precisionValue};
Options options = Options::createFromArgs(3, arguments);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == 2);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Short precision switch should return the right value")
{
char programName[] = "taptempo";
char precisionSwitch[] = "-p";
char precisionValue[] = "2";
char* arguments[3] = {programName, precisionSwitch, precisionValue};
Options options = Options::createFromArgs(3, arguments);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == 2);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Wrong precision switch should return the default value")
{
char programName[] = "taptempo";
char precisionSwitch[] = "--precision";
char precisionValue[] = "0";
char* arguments[3] = {programName, precisionSwitch, precisionValue};
Options options = Options::createFromArgs(3, arguments);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Out of bound precision switch should return the max value")
{
char programName[] = "taptempo";
char precisionSwitch[] = "--precision";
char precisionValue[] = "10";
char* arguments[3] = {programName, precisionSwitch, precisionValue};
Options options = Options::createFromArgs(3, arguments);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == MAX_PRECISION);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Sample size switch should return the right value")
{
char programName[] = "taptempo";
char sampleSizeSwitch[] = "--sample-size";
char sampleSizeValue[] = "10";
char* arguments[3] = {programName, sampleSizeSwitch, sampleSizeValue};
Options options = Options::createFromArgs(3, arguments);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == 10);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Short sample size switch should return the right value")
{
char programName[] = "taptempo";
char sampleSizeSwitch[] = "-s";
char sampleSizeValue[] = "10";
char* arguments[3] = {programName, sampleSizeSwitch, sampleSizeValue};
Options options = Options::createFromArgs(3, arguments);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == 10);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Wrong sample size switch should return the default value")
{
char programName[] = "taptempo";
char sampleSizeSwitch[] = "--sample-size";
char sampleSizeValue[] = "0";
char* arguments[3] = {programName, sampleSizeSwitch, sampleSizeValue};
Options options = Options::createFromArgs(3, arguments);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Reset time switch should return the right value")
{
char programName[] = "taptempo";
char resetTimeSwitch[] = "--reset-time";
char resetTimeValue[] = "10";
char* arguments[3] = {programName, resetTimeSwitch, resetTimeValue};
Options options = Options::createFromArgs(3, arguments);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == 10);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Short reset time switch should return the right value")
{
char programName[] = "taptempo";
char resetTimeSwitch[] = "-r";
char resetTimeValue[] = "10";
char* arguments[3] = {programName, resetTimeSwitch, resetTimeValue};
Options options = Options::createFromArgs(3, arguments);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == 10);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("Wrong reset time switch should return the default value")
{
char programName[] = "taptempo";
char resetTimeSwitch[] = "-r";
char resetTimeValue[] = "-10";
char* arguments[3] = {programName, resetTimeSwitch, resetTimeValue};
Options options = Options::createFromArgs(3, arguments);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == false);
}
TEST_CASE("All switchs should return the right values")
{
char programName[] = "taptempo";
char sampleSizeSwitch[] = "-s";
char sampleSizeValue[] = "6";
char resetTimeSwitch[] = "--reset-time";
char resetTimeValue[] = "10";
char precisionSwitch[] = "--precision";
char precisionValue[] = "2";
char gameSwitch[] = "--game";
char* arguments[8] = {programName,
sampleSizeSwitch,
sampleSizeValue,
resetTimeSwitch,
resetTimeValue,
precisionSwitch,
precisionValue,
gameSwitch};
Options options = Options::createFromArgs(8, arguments);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == 2);
REQUIRE(options.getSampleSize() == 6);
REQUIRE(options.getResetTime() == 10);
REQUIRE(options.getIsGamingMode() == true);
}
TEST_CASE("Game switch should return the right value")
{
char programName[] = "taptempo";
char gameSwitch[] = "--game";
char* arguments[3] = {programName, gameSwitch};
Options options = Options::createFromArgs(2, arguments);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == true);
}
TEST_CASE("Short game switch should return the right value")
{
char programName[] = "taptempo";
char gameSwitch[] = "-g";
char* arguments[3] = {programName, gameSwitch};
Options options = Options::createFromArgs(2, arguments);
REQUIRE(options.getShouldExit() == false);
REQUIRE(options.getPrecision() == DEFAULT_PRECISION);
REQUIRE(options.getSampleSize() == DEFAULT_SAMPLE_SIZE);
REQUIRE(options.getResetTime() == DEFAULT_RESET_TIME);
REQUIRE(options.getIsGamingMode() == true);
}
|