MNN/test/core/AutoStorageTest.cpp

38 lines
1.0 KiB
C++
Raw Normal View History

2019-04-17 10:49:11 +08:00
//
// AutoStorageTest.cpp
// MNNTests
//
// Created by MNN on 2019/01/17.
// Copyright © 2018, Alibaba Group Holding Limited
//
#include <stdio.h>
#include "MNNTestSuite.h"
2020-11-05 16:41:56 +08:00
#include "core/AutoStorage.h"
2019-04-17 10:49:11 +08:00
using namespace MNN;
class AutoStorageTest : public MNNTestCase {
public:
virtual ~AutoStorageTest() = default;
virtual bool run(int precision) {
2019-04-17 10:49:11 +08:00
AutoStorage<int> storage(50);
MNNTEST_ASSERT(storage.size() == 50);
2019-04-17 10:49:11 +08:00
storage.get()[40] = 999;
MNNTEST_ASSERT(storage.get()[40] == 999);
2019-04-17 10:49:11 +08:00
storage.clear();
MNNTEST_ASSERT(storage.get()[40] == 0);
2019-04-17 10:49:11 +08:00
storage.release();
MNNTEST_ASSERT(storage.size() == 0);
2019-04-17 10:49:11 +08:00
storage.reset(100);
MNNTEST_ASSERT(storage.size() == 100);
2019-04-17 10:49:11 +08:00
auto pointer = (int *)MNNMemoryAllocAlign(50 * sizeof(int), MNN_MEMORY_ALIGN_DEFAULT);
storage.set(pointer, 40);
MNNTEST_ASSERT(storage.size() == 40);
MNNTEST_ASSERT(storage.get() == pointer);
return true;
2019-04-17 10:49:11 +08:00
}
};
MNNTestSuiteRegister(AutoStorageTest, "core/auto_storage");