X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=include%2Fsdl%2Ftst%2Fmockableasyncstorage.hpp;fp=include%2Fsdl%2Ftst%2Fmockableasyncstorage.hpp;h=7c0d0ea730b6ae9f07c94ebc93cf77263b905374;hb=91a224f190867869d2d0b14a5f96e44a0593e682;hp=0000000000000000000000000000000000000000;hpb=02cf8dfcafb7380cda35beaa2aad783ffea87fa3;p=ric-plt%2Fsdl.git diff --git a/include/sdl/tst/mockableasyncstorage.hpp b/include/sdl/tst/mockableasyncstorage.hpp new file mode 100644 index 0000000..7c0d0ea --- /dev/null +++ b/include/sdl/tst/mockableasyncstorage.hpp @@ -0,0 +1,82 @@ +/* + Copyright (c) 2018-2020 Nokia. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/* + * This source code is part of the near-RT RIC (RAN Intelligent Controller) + * platform project (RICP). +*/ + +#ifndef SHAREDDATALAYER_TST_MOCKABLEASYNCSTORAGE_HPP_ +#define SHAREDDATALAYER_TST_MOCKABLEASYNCSTORAGE_HPP_ + +#include +#include +#include + +namespace shareddatalayer +{ + namespace tst + { + /** + * @brief Helper class for mocking AsyncStorage + * + * MockableAsyncStorage can be used in application's unit tests to mock AsyncStorage. + * MockableAsyncStorage guarantees that even if new functions are added into + * AsyncStorage, existing unit test cases do not have to be modified unless + * those new functions are used. + * + * If a function is not mocked but called in unit tests, then the call + * will be logged and the process will abort. + */ + class MockableAsyncStorage: public AsyncStorage + { + public: + MockableAsyncStorage() { } + + virtual int fd() const override { logAndAbort(__PRETTY_FUNCTION__); } + + virtual void handleEvents() override { logAndAbort(__PRETTY_FUNCTION__); } + + virtual void waitReadyAsync(const Namespace&, const ReadyAck&) override { logAndAbort(__PRETTY_FUNCTION__); } + + virtual void setAsync(const Namespace&, const DataMap&, const ModifyAck&) override { logAndAbort(__PRETTY_FUNCTION__); } + + virtual void setIfAsync(const Namespace&, const Key&, const Data&, const Data&, const ModifyIfAck&) override { logAndAbort(__PRETTY_FUNCTION__); } + + virtual void setIfNotExistsAsync(const Namespace&, const Key&, const Data&, const ModifyIfAck&) override { logAndAbort(__PRETTY_FUNCTION__); } + + virtual void getAsync(const Namespace&, const Keys&, const GetAck&) override { logAndAbort(__PRETTY_FUNCTION__); } + + virtual void removeAsync(const Namespace&, const Keys&, const ModifyAck&) override { logAndAbort(__PRETTY_FUNCTION__); } + + virtual void removeIfAsync(const Namespace&, const Key&, const Data&, const ModifyIfAck&) override { logAndAbort(__PRETTY_FUNCTION__); } + + virtual void findKeysAsync(const Namespace&, const std::string&, const FindKeysAck&) override { logAndAbort(__PRETTY_FUNCTION__); } + + virtual void removeAllAsync(const Namespace&, const ModifyAck&) override { logAndAbort(__PRETTY_FUNCTION__); } + + private: + static void logAndAbort(const char* function) noexcept __attribute__ ((__noreturn__)) + { + std::cerr << "MockableAsyncStorage: calling not-mocked function " + << function << ", aborting" << std::endl; + abort(); + } + }; + } +} + +#endif