Path: blob/main/test/browser/test_idbstore_sync.c
4150 views
/*1* Copyright 2015 The Emscripten Authors. All rights reserved.2* Emscripten is available under two separate licenses, the MIT license and the3* University of Illinois/NCSA Open Source License. Both these licenses can be4* found in the LICENSE file.5*/67#include <stdio.h>8#include <string.h>9#include <assert.h>10#include <stdlib.h>1112#include <emscripten.h>1314#define DB "THE_DB"1516void test() {17void *buffer;18int num, error, exists;19int sum = 0;2021printf("storing %s\n", SECRET);22emscripten_idb_store(DB, "the_secret", SECRET, strlen(SECRET)+1, &error);23assert(!error);24sum++;2526printf("checking\n");27exists = 5555;28emscripten_idb_exists(DB, "the_secret", &exists, &error);29assert(exists != 5555);30assert(!error);31assert(exists);32sum++;3334printf("loading\n");35emscripten_idb_load(DB, "the_secret", &buffer, &num, &error);36assert(!error);37char *ptr = buffer;38printf("loaded %s\n", ptr);39assert(num == strlen(SECRET)+1);40assert(strcmp(ptr, SECRET) == 0);41free(buffer);42sum++;4344printf("deleting the_secret\n");45emscripten_idb_delete(DB, "the_secret", &error);46assert(!error);47sum++;4849printf("loading, should fail as we deleted\n");50emscripten_idb_load(DB, "the_secret", &buffer, &num, &error);51assert(error); // expected error!52sum++;5354printf("storing %s again\n", SECRET);55emscripten_idb_store(DB, "the_secret", SECRET, strlen(SECRET)+1, &error);56assert(!error);57sum++;5859printf("clearing the store\n");60emscripten_idb_clear(DB, &error);61assert(!error);62sum++;6364printf("last checking\n");65emscripten_idb_exists(DB, "the_secret", &exists, &error);66assert(!error);67assert(!exists);68sum++;6970REPORT_RESULT(sum);71}7273void never() {74EM_ASM({ alert('this should never be reached! runtime must not be shut down!') });75assert(0);76while (1) {}77}7879int main() {80atexit(never);81test();82return 0;83}84858687