yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie HermaszewskaCorrect include dir for libslang (#5539)7b570feed

master
1.4 KiB63 linesraw
1// unit-test-io.cpp
2
3#include "../../source/core/slang-io.h"
4#include "unit-test/slang-unit-test.h"
5
6using namespace Slang;
7
8static SlangResult _checkGenerateTemporary()
9{
10    /// Test temporary file functionality
11
12    List<String> paths;
13
14    for (Index i = 0; i < 10; ++i)
15    {
16        String path;
17        SLANG_RETURN_ON_FAIL(File::generateTemporary(toSlice("slang-check"), path));
18
19        // The path should exist exist
20        SLANG_CHECK(File::exists(path));
21
22        if (paths.contains(path))
23        {
24            return SLANG_FAIL;
25        }
26
27        paths.add(path);
28    }
29
30    // It should be possible to write to the temporary files
31    for (auto& path : paths)
32    {
33        SLANG_RETURN_ON_FAIL(File::writeAllText(path, path));
34    }
35    // It should be possible to read from the temporary files
36
37    for (auto& path : paths)
38    {
39        String contents;
40        SLANG_RETURN_ON_FAIL(File::readAllText(path, contents))
41
42        SLANG_CHECK(contents == path);
43    }
44
45    // Remove all the temporary files
46    for (auto& path : paths)
47    {
48        SLANG_CHECK(File::exists(path));
49
50        const auto removeResult = File::remove(path);
51        SLANG_CHECK(SLANG_SUCCEEDED(removeResult));
52
53        // Check remove worked
54        SLANG_CHECK(!File::exists(path));
55    }
56
57    return SLANG_OK;
58}
59
60SLANG_UNIT_TEST(io)
61{
62    SLANG_CHECK(SLANG_SUCCEEDED(_checkGenerateTemporary()));
63}