Util/Macros: replacement for GLib's G_N_ELEMENTS()

This commit is contained in:
Max Kellermann
2013-10-15 22:04:17 +02:00
parent 77429b6dd3
commit 509f8dab89
19 changed files with 100 additions and 58 deletions

View File

@@ -18,6 +18,7 @@
*/
#include "util/byte_reverse.h"
#include "util/Macros.hxx"
#include <glib.h>
@@ -26,10 +27,10 @@ test_byte_reverse_2(void)
{
static const char src[] = "123456";
static const char result[] = "214365";
static uint8_t dest[G_N_ELEMENTS(src)];
static uint8_t dest[ARRAY_SIZE(src)];
reverse_bytes(dest, (const uint8_t *)src,
(const uint8_t *)(src + G_N_ELEMENTS(src) - 1), 2);
(const uint8_t *)(src + ARRAY_SIZE(src) - 1), 2);
g_assert_cmpstr((const char *)dest, ==, result);
}
@@ -38,10 +39,10 @@ test_byte_reverse_3(void)
{
static const char src[] = "123456";
static const char result[] = "321654";
static uint8_t dest[G_N_ELEMENTS(src)];
static uint8_t dest[ARRAY_SIZE(src)];
reverse_bytes(dest, (const uint8_t *)src,
(const uint8_t *)(src + G_N_ELEMENTS(src) - 1), 3);
(const uint8_t *)(src + ARRAY_SIZE(src) - 1), 3);
g_assert_cmpstr((const char *)dest, ==, result);
}
@@ -50,10 +51,10 @@ test_byte_reverse_4(void)
{
static const char src[] = "12345678";
static const char result[] = "43218765";
static uint8_t dest[G_N_ELEMENTS(src)];
static uint8_t dest[ARRAY_SIZE(src)];
reverse_bytes(dest, (const uint8_t *)src,
(const uint8_t *)(src + G_N_ELEMENTS(src) - 1), 4);
(const uint8_t *)(src + ARRAY_SIZE(src) - 1), 4);
g_assert_cmpstr((const char *)dest, ==, result);
}
@@ -62,10 +63,10 @@ test_byte_reverse_5(void)
{
static const char src[] = "1234567890";
static const char result[] = "5432109876";
static uint8_t dest[G_N_ELEMENTS(src)];
static uint8_t dest[ARRAY_SIZE(src)];
reverse_bytes(dest, (const uint8_t *)src,
(const uint8_t *)(src + G_N_ELEMENTS(src) - 1), 5);
(const uint8_t *)(src + ARRAY_SIZE(src) - 1), 5);
g_assert_cmpstr((const char *)dest, ==, result);
}

View File

@@ -2,6 +2,7 @@
#include "Queue.hxx"
#include "Song.hxx"
#include "Directory.hxx"
#include "util/Macros.hxx"
#include <glib.h>
@@ -54,10 +55,10 @@ main(gcc_unused int argc, gcc_unused char **argv)
struct queue queue(32);
for (unsigned i = 0; i < G_N_ELEMENTS(songs); ++i)
for (unsigned i = 0; i < ARRAY_SIZE(songs); ++i)
queue.Append(&songs[i], 0);
assert(queue.GetLength() == G_N_ELEMENTS(songs));
assert(queue.GetLength() == ARRAY_SIZE(songs));
/* priority=10 for 4 items */
@@ -75,7 +76,7 @@ main(gcc_unused int argc, gcc_unused char **argv)
assert(queue.PositionToOrder(i) < 4);
}
for (unsigned i = 8; i < G_N_ELEMENTS(songs); ++i) {
for (unsigned i = 8; i < ARRAY_SIZE(songs); ++i) {
assert(queue.PositionToOrder(i) >= 4);
}