File: test_util_reallocandappend.c

package info (click to toggle)
portsentry 2.0.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,396 kB
  • sloc: ansic: 6,473; sh: 916; perl: 18; makefile: 5
file content (30 lines) | stat: -rw-r--r-- 671 bytes parent folder | download
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
30
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include "../src/util.h"

void TestReallocAndAppend(void);

void TestReallocAndAppend(void) {
  size_t len = 0;
  char *buf = NULL;

  buf = ReallocAndAppend(buf, &len, "Hello %s", "World");
  assert(buf != NULL);
  assert(strcmp(buf, "Hello World") == 0);

  char *new_buf = ReallocAndAppend(buf, &len, ", %s!", "User");
  assert(new_buf != NULL);
  assert(strcmp(new_buf, "Hello World, User!") == 0);

  assert(ReallocAndAppend(NULL, NULL, "test") == NULL);
  assert(ReallocAndAppend(buf, &len, NULL) == NULL);

  free(new_buf);
}

int main(void) {
  TestReallocAndAppend();
  return 0;
}