aboutsummaryrefslogtreecommitdiff
path: root/lib/tst/mem.cc
blob: b233da83ef2f5675b44ef32aa630a292dc26d2a9 (plain)
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
#include <gtest/gtest.h>

#define restrict __restrict__

namespace libk {
#include "../memcpy.c"
#include "../memset.c"
} // namespace libk

TEST(mem, memset)
{
  auto *buffer = new unsigned char[2048];

  libk::memset(buffer, 0xae, sizeof(buffer));
  for (unsigned i = 0; i < sizeof(buffer); ++i) EXPECT_EQ(buffer[i], 0xae);

  delete[] buffer;
}

TEST(mem, memcpy)
{
  const unsigned char data[] = {0xde, 0xca, 0xfa, 0xde};
  auto *buffer = new unsigned char[sizeof(data)];

  memcpy(buffer, data, sizeof(data));
  for (unsigned i = 0; i < sizeof(data); ++i) EXPECT_EQ(buffer[i], data[i]);

  delete[] buffer;
}