aboutsummaryrefslogtreecommitdiff
path: root/lib/tst/mem.cc
blob: 7586a977ded4cf6d4daf47bf6bbcc56193e869fc (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 "../stdlib/memcpy.c"
#include "../stdlib/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;
}