ddat interop with dat js cable interop with cabal js ddat's frontend = dat-thang cable fe = cable-thang dillo support based on cel's dillo-dat bootstrap node xplatform support Signed-off-by: divo <418@cryspace.space>
63 lines
1.7 KiB
C
63 lines
1.7 KiB
C
#define _POSIX_C_SOURCE 200809L
|
|
#include "sleep_writer.h"
|
|
#include "sleep_crypto.h"
|
|
|
|
#include <assert.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#ifdef _WIN32
|
|
#include <direct.h>
|
|
#include <process.h>
|
|
static char *test_mkdtemp(char *path)
|
|
{
|
|
int i;
|
|
for (i = 0; i < 1000; i++) {
|
|
char candidate[512];
|
|
int n = snprintf(candidate, sizeof(candidate), "%s-%ld-%d", path,
|
|
(long)_getpid(), i);
|
|
if (n < 0 || (size_t)n >= sizeof(candidate)) return NULL;
|
|
if (_mkdir(candidate) == 0) { strcpy(path, candidate); return path; }
|
|
}
|
|
return NULL;
|
|
}
|
|
#else
|
|
#include <unistd.h>
|
|
#define test_mkdtemp mkdtemp
|
|
#endif
|
|
|
|
int main(void)
|
|
{
|
|
sleep_keypair_t keypair;
|
|
const uint8_t content[] = "block";
|
|
const uint8_t *blocks[] = {content};
|
|
const size_t lengths[] = {sizeof(content) - 1};
|
|
#ifdef _WIN32
|
|
char directory[] = "build/windows/datgpt-writer";
|
|
#else
|
|
char directory[] = "/tmp/datgpt-writer-XXXXXX";
|
|
#endif
|
|
assert(sleep_crypto_init() == 0);
|
|
assert(sleep_gen_keypair(&keypair) == 0);
|
|
assert(test_mkdtemp(directory) != NULL);
|
|
errno = 0;
|
|
assert(sleep_write_feed(directory, "../escape", blocks, lengths, 1, &keypair) == -1);
|
|
assert(errno == EINVAL);
|
|
errno = 0;
|
|
assert(sleep_write_feed(directory, "unsafe\\name", blocks, lengths, 1, &keypair) == -1);
|
|
assert(errno == EINVAL);
|
|
assert(sleep_write_feed(directory, "null-block", (const uint8_t *const[]){NULL},
|
|
(const size_t[]){1}, 1, &keypair) == -1);
|
|
assert(errno == EINVAL);
|
|
assert(sleep_write_feed(directory, "content", blocks, lengths, 1, &keypair) == 0);
|
|
{
|
|
char path[512];
|
|
struct stat st;
|
|
assert(snprintf(path, sizeof(path), "%s/content.data", directory) > 0);
|
|
assert(stat(path, &st) == 0 && st.st_size == (off_t)(sizeof(content) - 1));
|
|
}
|
|
return 0;
|
|
}
|