Adding Tests to Characterize Existing Behavior

We need to change code in writeSamples. Let’s start with a couple tests!

wav/6/WavReaderTest.cpp
 
#include "CppUTest/TestHarness.h"
 
#include "WavReader.h"
 
#include <iostream>
 
#include <string>
 
#include <sstream>
 
 
using​ ​namespace​ std;
 
 
TEST_GROUP(WavReader_WriteSamples)
 
{
 
WavReader reader{​""​,​""​};
 
ostringstream out;
 
};
 
 
TEST(WavReader_WriteSamples, WritesSingleSample) {
 
char​ data[] { ​"abcd"​ };
 
uint32_t bytesPerSample { 1 };
 
uint32_t startingSample { 0 };
 
uint32_t samplesToWrite { 1 };
 
reader.writeSamples(&out, data, startingSample, samplesToWrite, bytesPerSample);
 
CHECK_EQUAL(​"a"​, out.str());
 
}
 
 
TEST(WavReader_WriteSamples, WritesMultibyteSampleFromMiddle) ...

Get Modern C++ Programming with Test-Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.