Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions examples/include/CircularBuffer.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
#ifndef INCLUDED_CIRCULARBUFFER_HPP
#define INCLUDED_CIRCULARBUFFER_HPP

///////////////////////////////////////////////////////////////////////////////
//
// CircularBuffer.h
//
// CircularBuffer is responsible for ...
//
///////////////////////////////////////////////////////////////////////////////
#include <stddef.h>

class Printer;

class CircularBuffer
{
public:
explicit CircularBuffer(int capacity = default_capacity);
explicit CircularBuffer(size_t capacity = default_capacity);
virtual ~CircularBuffer();

CircularBuffer(const CircularBuffer&) = delete;
Expand All @@ -23,16 +18,16 @@ class CircularBuffer
int get();
bool is_empty() const;
bool is_full() const;
int capacity() const;
int next(int i) const;
size_t capacity() const;
size_t next(size_t i) const;
void print(Printer* p);

private:
int index_{ 0 };
int outdex_{ 0 };
size_t index_{ 0 };
size_t outdex_{ 0 };
int* buffer_;
int capacity_;
static constexpr int default_capacity = 5;
size_t capacity_;
static constexpr size_t default_capacity = 5;
bool empty_{ true };
bool full_{ false };
};
Expand Down
14 changes: 7 additions & 7 deletions examples/src/CircularBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

#include <stddef.h>

CircularBuffer::CircularBuffer(int capacity)
CircularBuffer::CircularBuffer(size_t capacity)
: capacity_(capacity)

{
buffer_ = new int[static_cast<size_t>(this->capacity_)];
buffer_ = new int[this->capacity_];
}

CircularBuffer::~CircularBuffer()
Expand Down Expand Up @@ -53,12 +53,12 @@ int CircularBuffer::get()
return result;
}

int CircularBuffer::capacity() const
size_t CircularBuffer::capacity() const
{
return capacity_;
}

int CircularBuffer::next(int i) const
size_t CircularBuffer::next(size_t i) const
{
if (++i >= capacity_) {
i = 0;
Expand All @@ -70,14 +70,14 @@ void CircularBuffer::print(Printer* p)
{
p->print("Circular buffer content:\n<");

int print_index = outdex_;
int count = index_ - outdex_;
size_t print_index = outdex_;
size_t count = index_ - outdex_;

if (!empty_ && (index_ <= outdex_)) {
count = capacity_ - (outdex_ - index_);
}

for (int i = 0; i < count; i++) {
for (size_t i = 0; i < count; i++) {
p->print(buffer_[print_index]);
print_index = next(print_index);
if (i + 1 != count) {
Expand Down
20 changes: 10 additions & 10 deletions examples/tests/CircularBuffer.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ TEST_GROUP(CircularBuffer)
void setup() override { buffer = new CircularBuffer(); }
void teardown() override { delete buffer; }

void fill_the_queue(int seed, int how_many) const
void fill_the_queue(int seed, size_t how_many) const
{
for (int i = 0; i < how_many; i++) {
buffer->put(seed + i);
for (size_t i = 0; i < how_many; i++) {
buffer->put(seed + static_cast<int>(i));
}
}
void remove_from_queue(int how_many) const
void remove_from_queue(size_t how_many) const
{
for (int i = 0; i < how_many; i++) {
for (size_t i = 0; i < how_many; i++) {
buffer->get();
}
}
Expand Down Expand Up @@ -62,8 +62,8 @@ TEST(CircularBuffer, GetPutAFew)

TEST(CircularBuffer, Capacity)
{
CircularBuffer b(2);
CHECK_EQUAL(2, b.capacity());
CircularBuffer b(2U);
CHECK_EQUAL(2U, b.capacity());
}

TEST(CircularBuffer, IsFull)
Expand Down Expand Up @@ -101,12 +101,12 @@ TEST(CircularBuffer, WrapAround)

TEST(CircularBuffer, PutToFull)
{
int capacity = buffer->capacity();
size_t capacity = buffer->capacity();
fill_the_queue(900, capacity);
buffer->put(9999);

for (int i = 0; i < buffer->capacity() - 1; i++) {
CHECK_EQUAL(i + 900 + 1, buffer->get());
for (size_t i = 0; i < buffer->capacity() - 1; i++) {
CHECK_EQUAL(static_cast<int>(i) + 900 + 1, buffer->get());
}

CHECK_EQUAL(9999, buffer->get());
Expand Down
2 changes: 0 additions & 2 deletions include/mu/tiny/String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ MUTINY_EXPORT size_t strlen(const char* str);
/** @brief Return a pointer to the first @p s2 in @p s1, or null. */
MUTINY_EXPORT const char* strstr(const char* s1, const char* s2);

/** @brief Parse @p str as a signed long integer. */
MUTINY_EXPORT long strtol(const char* str);
/** @brief Parse @p str as an unsigned long integer. */
MUTINY_EXPORT unsigned long strtoul(const char* str);
/** @brief Compare @p s1 and @p s2; return negative, zero, or positive. */
Expand Down
33 changes: 17 additions & 16 deletions include/mu/tiny/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C"
Expand Down Expand Up @@ -294,7 +295,7 @@ extern "C"
bool actual,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -310,7 +311,7 @@ extern "C"
int actual,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -326,7 +327,7 @@ extern "C"
unsigned int actual,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -342,7 +343,7 @@ extern "C"
long actual,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -358,7 +359,7 @@ extern "C"
unsigned long actual,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -374,7 +375,7 @@ extern "C"
long long actual,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -390,7 +391,7 @@ extern "C"
unsigned long long actual,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -408,7 +409,7 @@ extern "C"
double threshold,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -424,7 +425,7 @@ extern "C"
char actual,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -440,7 +441,7 @@ extern "C"
unsigned char actual,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -456,7 +457,7 @@ extern "C"
signed char actual,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -472,7 +473,7 @@ extern "C"
const char* actual,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -488,7 +489,7 @@ extern "C"
const void* actual,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -506,7 +507,7 @@ extern "C"
size_t size,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -518,7 +519,7 @@ extern "C"
MUTINY_EXPORT void mutiny_fail(
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand All @@ -534,7 +535,7 @@ extern "C"
const char* condition_string,
const char* text,
const char* file_name,
size_t line_number
int_least32_t line_number
);

/**
Expand Down
8 changes: 4 additions & 4 deletions include/mu/tiny/test/CommandLineArguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class MUTINY_EXPORT CommandLineArguments
/** @return true if `-rs` (run skipped tests) was passed. */
bool is_run_skipped() const;
/** @return The number of times to repeat the full test suite (`-r N`). */
size_t get_repeat_count() const;
unsigned int get_repeat_count() const;
/** @return true if `-s` (shuffle) was passed. */
bool is_shuffling() const;
/** @return true if tests should run in reverse order (`-rv`). */
Expand All @@ -85,7 +85,7 @@ class MUTINY_EXPORT CommandLineArguments
/** @return true if exceptions should be re-thrown after being caught. */
bool is_rethrowing_exceptions() const;
/** @return The seed used when shuffling (0 means time-seeded). */
size_t get_shuffle_seed() const;
unsigned int get_shuffle_seed() const;
/** @return The head of the group filter chain, or nullptr. */
const Filter* get_group_filters() const;
/** @return The head of the name filter chain, or nullptr. */
Expand All @@ -112,8 +112,8 @@ class MUTINY_EXPORT CommandLineArguments
bool rethrow_exceptions_{ true };
bool shuffling_{ false };
bool shuffling_pre_seeded_{ false };
size_t repeat_{ 1 };
size_t shuffle_seed_{ 0 };
unsigned int repeat_{ 1 };
unsigned int shuffle_seed_{ 0 };
Filter* group_filters_{ nullptr };
Filter* name_filters_{ nullptr };
void set_repeat_count(int argc, const char* const* argv, int& index);
Expand Down
2 changes: 1 addition & 1 deletion include/mu/tiny/test/ExpectFailShell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MUTINY_EXPORT ExpectFailShell : public Shell
const char* group_name,
const char* test_name,
const char* file_name,
size_t line_number
int_least32_t line_number
);
~ExpectFailShell() override = default;
ExpectFailShell(const ExpectFailShell&) = delete;
Expand Down
Loading