structure.cc
block.cc
generator.cc
- proxy_gen.cc
- stub_gen.cc
+ cs_gen_base.cc
+ cs_proxy_gen.cc
+ cs_stub_gen.cc
main.cc
)
ADD_EXECUTABLE(tidlc ${BISON_TIDLC_OUTPUTS} ${FLEX_TIDLC_OUTPUTS} ${SOURCES})
TARGET_LINK_LIBRARIES(tidlc ${LIBPKGS_LDFLAGS})
INSTALL(TARGETS tidlc DESTINATION bin)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/copyright.cb DESTINATION share/tidl)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cs_interop.cb DESTINATION share/tidl)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cs_proxy_interop.cb DESTINATION share/tidl)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cs_stub_interop.cb DESTINATION share/tidl)
--- /dev/null
+/*
+ * This file is generated by tidlc.
+ * Please do not modify it directly.
+ */
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include <vector>
+
+#include "idlc/cs_gen_base.h"
+
+namespace tidl {
+
+CsGeneratorBase::CsGeneratorBase(std::shared_ptr<Document> doc)
+ : Generator(doc) {
+ type_map_ = {
+ {"char", "byte"}, {"int", "int"}, {"short", "short"},
+ {"long", "long"}, {"string", "string"}, {"bool", "bool"},
+ {"list", "List"}, {"float","float"}, {"double", "double"},
+ {"bundle", "Bundle"}
+ };
+}
+
+void CsGeneratorBase::GenStructures(std::ofstream& stream) {
+ for (auto& i : GetDocument().GetBlocks()) {
+ if (i->GetType() != Block::TYPE_STRUCTURE)
+ continue;
+ Structure& st = static_cast<Structure&>(*i);
+ GenStructure(stream, st);
+ stream << std::endl;
+ }
+}
+
+void CsGeneratorBase::GenStructure(std::ofstream& stream, const Structure& st) {
+ std::vector<std::string> v;
+ stream << TAB <<"sealed class " << st.GetID() << std::endl;
+ stream << TAB <<"{" << std::endl;
+ for (auto& i : st.GetElements().GetElms()) {
+ stream << TAB << TAB <<"public "
+ << ConvertTypeToString(i->GetType()) << " "
+ << i->GetID() << " { get; set; }" << std::endl;
+ if (i->GetType().ToString() == "bundle") {
+ v.push_back(i->GetID() + " = " + "new Bundle()");
+ }
+ }
+
+ stream << TAB << TAB << "public " + st.GetID() << "()" << std::endl;
+ stream << TAB << TAB << "{" << std::endl;
+ for (auto& i : v) {
+ stream << TAB << TAB << TAB << i << std::endl;
+ }
+ stream << TAB << TAB << "}" << std::endl;
+
+ stream << TAB << "}" << std::endl;
+}
+
+std::string CsGeneratorBase::ConvertTypeToString(const BaseType& type) {
+ if (type.IsUserDefinedType())
+ return type.ToString();
+
+ if (type.GetMetaType() != nullptr)
+ return type_map_[type.ToString()] + "<" +
+ ConvertTypeToString(*(type.GetMetaType())) + ">";
+
+ return type_map_[type.ToString()];
+}
+
+} // namespace tidl
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef IDLC_CS_GEN_BASE_H_
+#define IDLC_CS_GEN_BASE_H_
+
+#include <memory>
+#include <string>
+#include <map>
+
+#include "idlc/type.h"
+#include "idlc/structure.h"
+#include "idlc/generator.h"
+
+namespace tidl {
+
+class CsGeneratorBase : public Generator {
+ public:
+ explicit CsGeneratorBase(std::shared_ptr<Document> doc);
+ virtual ~CsGeneratorBase() = default;
+
+ void GenStructures(std::ofstream& stream);
+ void GenStructure(std::ofstream& stream, const Structure& st);
+ std::string ConvertTypeToString(const BaseType& type);
+
+ protected:
+ const std::string TAB = " ";
+ private:
+ std::map<std::string, std::string> type_map_;
+};
+
+} // namespace tidl
+
+#endif // IDLC_CS_GEN_BASE_H_
--- /dev/null
+internal static partial class Interop
+{
+ internal static partial class LibRPCPort
+ {
+ internal static partial class Libraries
+ {
+ public const string RpcPort = "librpc-port.so.1";
+ }
+
+ internal static partial class Parcel
+ {
+ //int rpc_port_parcel_create(rpc_port_parcel_h *h);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_create")]
+ internal static extern int Create(out IntPtr handle);
+
+ //int rpc_port_parcel_create_from_port(rpc_port_parcel_h *h, rpc_port_h port);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_create_from_port")]
+ internal static extern int CreateFromPort(out IntPtr parcelHandle, IntPtr portHandle);
+
+ //int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_send")]
+ internal static extern int Send(IntPtr parcelHandle, IntPtr portHandle);
+
+ //int rpc_port_parcel_destroy(rpc_port_parcel_h h);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_destroy")]
+ internal static extern int Destroy(IntPtr handle);
+
+ //int rpc_port_parcel_write_byte(rpc_port_parcel_h h, char b);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_byte")]
+ internal static extern int WriteByte(IntPtr parcelHandle, byte b);
+
+ //int rpc_port_parcel_write_int16(rpc_port_parcel_h h, short i);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_int16")]
+ internal static extern int WriteInt16(IntPtr parcelHandle, short i);
+
+ //int rpc_port_parcel_write_int32(rpc_port_parcel_h h, int i);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_int32")]
+ internal static extern int WriteInt32(IntPtr parcelHandle, int i);
+
+ //int rpc_port_parcel_write_int64(rpc_port_parcel_h h, int i);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_int64")]
+ internal static extern int WriteInt64(IntPtr parcelHandle, long i);
+
+ //int rpc_port_parcel_write_float(rpc_port_parcel_h h, float f);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_float")]
+ internal static extern int WriteFloat(IntPtr parcelHandle, float f);
+
+ //int rpc_port_parcel_write_double(rpc_port_parcel_h h, double d);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_double")]
+ internal static extern int WriteDouble(IntPtr parcelHandle, double d);
+
+ //int rpc_port_parcel_write_string(rpc_port_parcel_h h, const char* str);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_string")]
+ internal static extern int WriteString(IntPtr parcelHandle, string str);
+
+ //int rpc_port_parcel_write_bool(rpc_port_parcel_h h, bool b);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_bool")]
+ internal static extern int WriteBool(IntPtr parcelHandle, bool b);
+
+ //int rpc_port_parcel_write_bundle(rpc_port_parcel_h h, bundle* b);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_bundle")]
+ internal static extern int WriteBundle(IntPtr parcelHandle, IntPtr b);
+
+ //int rpc_port_parcel_write_array_count(rpc_port_parcel_h h, int count);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_array_count")]
+ internal static extern int WriteArrayCount(IntPtr parcelHandle, int count);
+
+ //int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char* b);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_byte")]
+ internal static extern int ReadByte(IntPtr parcelHandle, out byte b);
+
+ //int rpc_port_parcel_read_int16(rpc_port_parcel_h h, short *i);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_int16")]
+ internal static extern int ReadInt16(IntPtr parcelHandle, out short i);
+
+ //int rpc_port_parcel_read_int32(rpc_port_parcel_h h, int* i);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_int32")]
+ internal static extern int ReadInt32(IntPtr parcelHandle, out int i);
+
+ //int rpc_port_parcel_read_int64(rpc_port_parcel_h h, long long* i);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_int64")]
+ internal static extern int ReadInt64(IntPtr parcelHandle, out long i);
+
+ //int rpc_port_parcel_read_float(rpc_port_parcel_h h, float *f);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_float")]
+ internal static extern int ReadFloat(IntPtr parcelHandle, out float f);
+
+ //int rpc_port_parcel_read_double(rpc_port_parcel_h h, double *d);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_double")]
+ internal static extern int ReadDouble(IntPtr parcelHandle, out double f);
+
+ //int rpc_port_parcel_read_string(rpc_port_parcel_h h, char** str);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_string")]
+ internal static extern int ReadString(IntPtr parcelHandle, out string str);
+
+ //int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle** b);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_bundle")]
+ internal static extern int ReadBundle(IntPtr parcelHandle, out IntPtr b);
+
+ //int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int *count);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_array_count")]
+ internal static extern int ReadArrayCount(IntPtr parcelHandle, out int count);
+ }
+#event
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include "idlc/cs_proxy_gen.h"
+
+namespace tidl {
+
+CsProxyGen::CsProxyGen(std::shared_ptr<Document> doc)
+ : CsGeneratorBase(doc) {}
+
+void CsProxyGen::OnInitGen(std::ofstream& stream) {
+ GenCodeBlock("copyright.cb");
+ stream << std::endl;
+ stream << "using System;" << std::endl
+ << "using System.Collections.Generic;" << std::endl
+ << "using System.Runtime.InteropServices;" << std::endl
+ << "using Tizen.Applications;" << std::endl << std::endl;
+ GenInterop(stream);
+ GenNamespace(stream);
+}
+
+void CsProxyGen::OnFiniGen(std::ofstream& stream) {
+}
+
+void CsProxyGen::GenNamespace(std::ofstream& stream) {
+ stream << "namespace RPCPort" << std::endl;
+ stream << "{" << std::endl;
+ GenStructures(stream);
+ stream << "} // RPCPort" << std::endl;
+}
+
+void CsProxyGen::GenInterop(std::ofstream& stream) {
+ GenCodeBlock("cs_interop.cb", [](Generator& gen, int pos) {
+ gen.GenCodeBlock("cs_proxy_interop.cb");
+ });
+}
+
+} // namespace tidl
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef IDLC_CS_PROXY_GEN_H_
+#define IDLC_CS_PROXY_GEN_H_
+
+#include <memory>
+#include <string>
+
+#include "idlc/cs_gen_base.h"
+
+namespace tidl {
+
+class CsProxyGen : public CsGeneratorBase {
+ public:
+ explicit CsProxyGen(std::shared_ptr<Document> doc);
+ virtual ~CsProxyGen() = default;
+
+ void OnInitGen(std::ofstream& stream) override;
+ void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+ void GenNamespace(std::ofstream& stream);
+ void GenInterop(std::ofstream& stream);
+
+};
+
+} // namespace tidl
+
+#endif // IDLC_CS_PROXY_GEN_H_
--- /dev/null
+ internal static partial class Proxy
+ {
+ //typedef void (*rpc_port_proxy_connected_event_cb)(const char *ep, const char* port_name, rpc_port_h port, void* data);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void ConnectedEventCallback(string endPoint, string port_name, IntPtr port, IntPtr data);
+
+ //typedef void (*rpc_port_proxy_disconnected_event_cb)(const char *ep, const char* port_name, void* data);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void DisconnectedEventCallback(string endPoint, string port_name, IntPtr data);
+
+ //typedef void (*rpc_port_proxy_rejected_event_cb) (const char* ep, const char* port_name, void* data);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void RejectedEventCallback(string endPoint, string port_name, IntPtr data);
+
+ //int rpc_port_proxy_create(rpc_port_proxy_h *h);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_create")]
+ internal static extern int Create(out IntPtr handle);
+
+ //int rpc_port_proxy_destroy(rpc_port_proxy_h h);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_destroy")]
+ internal static extern int Destroy(IntPtr handle);
+
+ //int rpc_port_proxy_connect(rpc_port_proxy_h h, const char *appid, const char* port);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_connect")]
+ internal static extern int Connect(IntPtr handle, string appId, string port);
+
+ //int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_connected_event_cb cb, void* data);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_connected_event_cb")]
+ internal static extern int AddConnectedEventCb(IntPtr handle, ConnectedEventCallback cb, IntPtr data);
+
+ //int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_disconnected_event_cb cb, void* data);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_disconnected_event_cb")]
+ internal static extern int AddDisconnectedEventCb(IntPtr handle, DisconnectedEventCallback cb, IntPtr data);
+
+ //int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_rejected_event_cb cb, void* data);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_rejected_event_cb")]
+ internal static extern int AddRejectedEventCb(IntPtr handle, RejectedEventCallback cb, IntPtr data);
+ }
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include "idlc/cs_stub_gen.h"
+
+namespace tidl {
+
+CsStubGen::CsStubGen(std::shared_ptr<Document> doc)
+ : CsGeneratorBase(doc) {}
+
+void CsStubGen::OnInitGen(std::ofstream& stream) {
+ GenCodeBlock("copyright.cb");
+ stream << std::endl;
+ stream << "using System;" << std::endl
+ << "using System.Collections.Generic;" << std::endl
+ << "using System.Runtime.InteropServices;" << std::endl
+ << "using Tizen.Applications;" << std::endl << std::endl;
+ GenInterop(stream);
+ GenNamespace(stream);
+}
+
+void CsStubGen::OnFiniGen(std::ofstream& stream) {}
+
+void CsStubGen::GenInterop(std::ofstream& stream) {
+ GenCodeBlock("cs_interop.cb", [](Generator& gen, int pos) {
+ gen.GenCodeBlock("cs_stub_interop.cb");
+ });
+}
+
+void CsStubGen::GenNamespace(std::ofstream& stream) {
+ stream << "namespace RPCPort" << std::endl;
+ stream << "{" << std::endl;
+ GenStructures(stream);
+ stream << "} // RPCPort" << std::endl;
+}
+
+} // namespace tidl
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef IDLC_STUB_GEN_H_
+#define IDLC_STUB_GEN_H_
+
+#include <memory>
+#include <string>
+
+#include "idlc/cs_gen_base.h"
+
+namespace tidl {
+
+class CsStubGen : public CsGeneratorBase {
+ public:
+ explicit CsStubGen(std::shared_ptr<Document> doc);
+ virtual ~CsStubGen() = default;
+
+ void OnInitGen(std::ofstream& stream) override;
+ void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+ void GenNamespace(std::ofstream& stream);
+ void GenInterop(std::ofstream& stream);
+};
+
+} // namespace tidl
+
+#endif // IDLC_STUB_GEN_H_
--- /dev/null
+ internal static partial class Stub
+ {
+ //typedef void (*rpc_port_stub_connected_event_cb)(const char *sender, void* data);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void ConnectedEventCallback(string sender, IntPtr data);
+
+ //typedef void (* rpc_port_stub_disconnected_event_cb) (const char* sender, void* data);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void DisconnectedEventCallback(string sender, IntPtr data);
+
+ //typedef void (* rpc_port_stub_received_event_cb) (const char* sender, rpc_port_h port, void* data);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate int ReceivedEventCallback(string sender, IntPtr port, IntPtr data);
+
+ //int rpc_port_stub_create(rpc_port_stub_h* h, const char* port_name);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_create")]
+ internal static extern int Create(out IntPtr handle, string portName);
+
+ //int rpc_port_stub_destroy(rpc_port_stub_h h);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_destroy")]
+ internal static extern int Destroy(IntPtr handle);
+
+ //int rpc_port_stub_listen(rpc_port_stub_h h);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_listen")]
+ internal static extern int Listen(IntPtr handle);
+
+ //int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h, rpc_port_stub_connected_event_cb cb, void* data);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_connected_event_cb")]
+ internal static extern int AddConnectedEventCb(IntPtr handle, ConnectedEventCallback cb, IntPtr data);
+
+ //int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h, rpc_port_stub_disconnected_event_cb cb, void* data);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_disconnected_event_cb")]
+ internal static extern int AddDisconnectedEventCb(IntPtr handle, DisconnectedEventCallback cb, IntPtr data);
+
+ //int rpc_port_stub_add_received_event_cb(rpc_port_stub_h h, rpc_port_stub_received_event_cb cb, void* data);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_received_event_cb")]
+ internal static extern int AddReceivedEventCb(IntPtr handle, ReceivedEventCallback cb, IntPtr data);
+ }
\ No newline at end of file
out_file_.open(FileName);
OnInitGen(out_file_);
- for (auto& block : doc_->GetBlocks()) {
- if (block->GetType() == Block::TYPE_INTERFACE) {
- Interface* interface = static_cast<Interface*>(block.get());
- OnInterfaceBegin(out_file_, interface->GetID(), interface->GetComments());
- for (auto& decl : interface->GetDeclarations().GetDecls()) {
- OnDeclarationGen(out_file_, decl->GetID(), decl->GetParameters(),
- decl->GetType(), decl->GetComments());
- }
- OnInterfaceEnd(out_file_, interface->GetID());
- } else if (block->GetType() == Block::TYPE_STRUCTURE) {
- Structure* structure = static_cast<Structure*>(block.get());
- OnStructureBegin(out_file_, structure->GetID(), structure->GetComments());
- for (auto& elm : structure->GetElements().GetElms()) {
- OnElementGen(out_file_, elm->GetID(), elm->GetType(),
- elm->GetComments());
- }
- OnStructureEnd(out_file_, structure->GetID());
+ OnFiniGen(out_file_);
+ out_file_.close();
+}
+
+void Generator::GenCodeBlock(std::string filename,
+ void (*cb)(Generator& gen, int pos)) {
+ std::ifstream cb_file;
+ std::string line;
+ int cnt = 1;
+
+ cb_file.open("/usr/share/tidl/" + filename);
+ if (!cb_file.is_open()) {
+ cb_file.open("../idlc/" + filename);
+ }
+
+ if (!cb_file.is_open())
+ return;
+
+ while (std::getline(cb_file, line)) {
+ if (line.find("#event") == 0) {
+ if (cb != nullptr)
+ cb(*this, cnt);
+ cnt++;
+ } else {
+ out_file_ << line << std::endl;
}
}
- OnFiniGen(out_file_);
- out_file_.close();
+ cb_file.close();
}
} // namespace tidl
virtual ~Generator() = default;
void Run(const std::string& file_name);
- virtual void OnInterfaceBegin(std::ofstream& stream,
- const std::string& id,
- const std::string& comments) = 0;
- virtual void OnInterfaceEnd(std::ofstream& stream, const std::string& id) = 0;
- virtual void OnDeclarationGen(std::ofstream& stream, const std::string& id,
- const Parameters& args,
- const BaseType& ret,
- const std::string& comments) = 0;
- virtual void OnStructureBegin(std::ofstream& stream,
- const std::string& id,
- const std::string& comments) = 0;
- virtual void OnStructureEnd(std::ofstream& stream, const std::string& id) = 0;
- virtual void OnElementGen(std::ofstream& stream, const std::string& id,
- const BaseType& type,
- const std::string& comments) = 0;
+ void GenCodeBlock(std::string filename,
+ void (*cb)(Generator& gen, int pos) = nullptr);
+
virtual void OnInitGen(std::ofstream& stream) = 0;
virtual void OnFiniGen(std::ofstream& stream) = 0;
protected:
+ const Document& GetDocument() {
+ return *doc_;
+ }
+
+ protected:
std::string FileName;
private:
#include <memory>
#include "idlc/parser.h"
-#include "idlc/proxy_gen.h"
-#include "idlc/stub_gen.h"
+#include "idlc/cs_proxy_gen.h"
+#include "idlc/cs_stub_gen.h"
namespace {
exit(1);
if (options->IsProxy()) {
- tidl::ProxyGen proxy(ps.GetDoc());
- proxy.Run(options->GetOutput());
+ if (options->GetLanguage() == "C#") {
+ tidl::CsProxyGen proxy(ps.GetDoc());
+ proxy.Run(options->GetOutput());
+ } else if (options->GetLanguage() == "C++") {
+ //TODO
+ } else if (options->GetLanguage() == "C") {
+ //TODO
+ }
} else {
- tidl::StubGen stub(ps.GetDoc());
- stub.Run(options->GetOutput());
+ if (options->GetLanguage() == "C#") {
+ tidl::CsStubGen stub(ps.GetDoc());
+ stub.Run(options->GetOutput());
+ } else if (options->GetLanguage() == "C++") {
+ //TODO
+ } else if (options->GetLanguage() == "C") {
+ //TODO
+ }
}
return 0;
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-#include "idlc/proxy_gen.h"
-
-namespace tidl {
-
-ProxyGen::ProxyGen(std::shared_ptr<Document> doc)
- : Generator(doc) {}
-
-void ProxyGen::OnDeclarationGen(std::ofstream& stream, const std::string& id,
- const Parameters& args,
- const BaseType& ret,
- const std::string& comments) {
- if (comments != "")
- stream << comments;
- stream << ret.ToString() << " " << interface_name_ + "_" + id << "(";
-
- bool first = true;
- for (auto& param : args.GetParams()) {
- if (!first)
- stream << ", ";
-
- stream << param->GetParameterType().GetBaseType().GetFullName() << " ";
- stream << param->GetID();
- first = false;
- }
-
- stream << ")" << std::endl;
- stream << "{" << std::endl;
- // TODO(jh9216.park) : generate body
-
- // Temp
- stream << "\treturn 0;" << std::endl;
-
- stream << "}" << std::endl;
- stream << std::endl;
-}
-
-void ProxyGen::OnInitGen(std::ofstream& stream) {
- // TODO(h.jhun) : Change header file
- stream << "#include <rpc-port.h>" << std::endl << std::endl;
-}
-
-void ProxyGen::OnFiniGen(std::ofstream& stream) {
-}
-
-void ProxyGen::OnInterfaceBegin(std::ofstream& stream,
- const std::string& id,
- const std::string& comments) {
- if (comments != "")
- stream << comments;
- interface_name_ = id;
-}
-
-void ProxyGen::OnInterfaceEnd(std::ofstream& stream, const std::string& id) {
- interface_name_ = "";
-}
-
-void ProxyGen::OnElementGen(std::ofstream& stream, const std::string& id,
- const BaseType& type, const std::string& comments) {
- if (comments != "")
- stream << "\t" << comments;
- stream << "\t" << type.GetFullName() << " " << id << ";" << std::endl;
-}
-
-void ProxyGen::OnStructureBegin(std::ofstream& stream, const std::string& id,
- const std::string& comments) {
- if (comments != "")
- stream << comments;
- stream << "typedef struct" << " " << id + "_t" << " " << "{" << std::endl;
-}
-
-void ProxyGen::OnStructureEnd(std::ofstream& stream, const std::string& id) {
- stream << "}" << " " << id << ";" << std::endl;
- stream << std::endl;
-}
-
-} // namespace tidl
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-#ifndef IDLC_PROXY_GEN_H_
-#define IDLC_PROXY_GEN_H_
-
-#include <memory>
-#include <string>
-
-#include "idlc/generator.h"
-
-namespace tidl {
-
-class ProxyGen : public Generator {
- public:
- explicit ProxyGen(std::shared_ptr<Document> doc);
- virtual ~ProxyGen() = default;
-
- void OnDeclarationGen(std::ofstream& stream, const std::string& id,
- const Parameters& args, const BaseType& ret,
- const std::string& comments) override;
- void OnInitGen(std::ofstream& stream) override;
- void OnFiniGen(std::ofstream& stream) override;
- void OnInterfaceBegin(std::ofstream& stream,
- const std::string& id,
- const std::string& comments) override;
- void OnInterfaceEnd(std::ofstream& stream, const std::string& id) override;
- void OnElementGen(std::ofstream& stream, const std::string& id,
- const BaseType& type,
- const std::string& comments) override;
- void OnStructureBegin(std::ofstream& stream, const std::string& id,
- const std::string& comments) override;
- void OnStructureEnd(std::ofstream& stream, const std::string& id) override;
-
- private:
- std::string ConvertTypeToCType(const BaseType& type);
-
- private:
- std::string interface_name_;
-};
-
-} // namespace tidl
-
-#endif // IDLC_PROXY_GEN_H_
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-#include "idlc/stub_gen.h"
-
-namespace tidl {
-
-StubGen::StubGen(std::shared_ptr<Document> doc)
- : Generator(doc) {}
-
-void StubGen::OnDeclarationGen(std::ofstream& stream, const std::string& id,
- const Parameters& args, const BaseType& ret,
- const std::string& comments) {}
-
-void StubGen::OnInitGen(std::ofstream& stream) {}
-
-void StubGen::OnFiniGen(std::ofstream& stream) {}
-
-void StubGen::OnInterfaceBegin(std::ofstream& stream,
- const std::string& id,
- const std::string& comments) {}
-
-void StubGen::OnInterfaceEnd(std::ofstream& stream, const std::string& id) {}
-
-void StubGen::OnElementGen(std::ofstream& stream, const std::string& id,
- const BaseType& type, const std::string& comments) {}
-
-void StubGen::OnStructureBegin(std::ofstream& stream,
- const std::string& id,
- const std::string& comments) {}
-
-void StubGen::OnStructureEnd(std::ofstream& stream, const std::string& id) {}
-
-} // namespace tidl
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-#ifndef IDLC_STUB_GEN_H_
-#define IDLC_STUB_GEN_H_
-
-#include <memory>
-#include <string>
-
-#include "idlc/generator.h"
-
-namespace tidl {
-
-class StubGen : public Generator {
- public:
- explicit StubGen(std::shared_ptr<Document> doc);
- virtual ~StubGen() = default;
-
- void OnDeclarationGen(std::ofstream& stream, const std::string& id,
- const Parameters& args, const BaseType& ret,
- const std::string& comments) override;
- void OnInitGen(std::ofstream& stream) override;
- void OnFiniGen(std::ofstream& stream) override;
- void OnInterfaceBegin(std::ofstream& stream,
- const std::string& id,
- const std::string& comments) override;
- void OnInterfaceEnd(std::ofstream& stream, const std::string& id) override;
- void OnElementGen(std::ofstream& stream, const std::string& id,
- const BaseType& type,
- const std::string& comments) override;
- void OnStructureBegin(std::ofstream& stream,
- const std::string& id,
- const std::string& comments) override;
- void OnStructureEnd(std::ofstream& stream, const std::string& id) override;
-};
-
-} // namespace tidl
-
-#endif // IDLC_STUB_GEN_H_
explicit BaseType(std::string name, std::string comments,
bool user_defined = false);
void SetMetaType(BaseType* type);
- const BaseType& GetMetaType() const {
- return *meta_type_;
+ const BaseType* GetMetaType() const {
+ return meta_type_.get();
}
std::string GetFullName() const {
Unit tests for TIDL
%define _share_dir /opt/usr/share
+%define _usr_share_dir /usr/share
%prep
%setup -q
%license LICENSE
%manifest %{name}.manifest
%{_bindir}/tidlc
+%{_usr_share_dir}/tidl/*.cb
%files tests
%manifest %{name}.manifest
../idlc/structure.cc
../idlc/block.cc
../idlc/generator.cc
- ../idlc/proxy_gen.cc
- ../idlc/stub_gen.cc
+ ../idlc/cs_gen_base.cc
+ ../idlc/cs_proxy_gen.cc
+ ../idlc/cs_stub_gen.cc
../idlc/parser.cc
)
interface_unittest.cc
structure_unittest.cc
generator_unittest.cc
- proxy_gen_unittest.cc
- stub_gen_unittest.cc
+ cs_proxy_gen_unittest.cc
+ cs_stub_gen_unittest.cc
parser_unittest.cc
main.cc
)
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include "idlc/parser.h"
+#include "idlc/cs_proxy_gen.h"
+
+class CsProxyGenTest : public testing::Test {
+ public:
+ tidl::Parser* ps = new tidl::Parser();
+
+ virtual void SetUp() {
+ ps = new tidl::Parser();
+ }
+
+ virtual void TearDown() {
+ delete ps;
+ }
+
+ bool FindStringFromFile(std::string filename, std::string str) {
+ std::ifstream cb_file(filename);
+ std::string line;
+
+ while (std::getline(cb_file, line)) {
+ if (line.find(str) == 0) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+};
+
+TEST_F(CsProxyGenTest, CsProxyGen_Constructor) {
+ bool ret = ps->ParseFromFile("test.tidl");
+ ASSERT_TRUE(ret);
+ tidl::CsProxyGen gen(ps->GetDoc());
+}
+
+TEST_F(CsProxyGenTest, CsProxyGen_Run) {
+ bool ret = ps->ParseFromFile("test.tidl");
+ ASSERT_TRUE(ret);
+ tidl::CsProxyGen gen(ps->GetDoc());
+ gen.Run("test.cs");
+
+ ASSERT_TRUE(FindStringFromFile("test.cs", "namespace RPCPort"));
+ ASSERT_TRUE(FindStringFromFile("test.cs", " internal static partial class Proxy"));
+ ASSERT_TRUE(FindStringFromFile("test.cs", " sealed class Student"));
+ ASSERT_TRUE(FindStringFromFile("test.cs", " public string name { get; set; }"));
+ ASSERT_TRUE(FindStringFromFile("test.cs", " sealed class Class"));
+ ASSERT_TRUE(FindStringFromFile("test.cs", " public List<Student> students { get; set; }"));
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include "idlc/parser.h"
+#include "idlc/cs_stub_gen.h"
+
+class CsStubGenTest : public testing::Test {
+ public:
+ tidl::Parser* ps = new tidl::Parser();
+
+ virtual void SetUp() {
+ ps = new tidl::Parser();
+ }
+
+ virtual void TearDown() {
+ delete ps;
+ }
+
+ bool FindStringFromFile(std::string filename, std::string str) {
+ std::ifstream cb_file(filename);
+ std::string line;
+
+ while (std::getline(cb_file, line)) {
+ if (line.find(str) == 0) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+};
+
+TEST_F(CsStubGenTest, CsStubGen_Constructor) {
+ bool ret = ps->ParseFromFile("test.tidl");
+ ASSERT_TRUE(ret);
+ tidl::CsStubGen gen(ps->GetDoc());
+}
+
+TEST_F(CsStubGenTest, CsStubGen_Run) {
+ bool ret = ps->ParseFromFile("test.tidl");
+ ASSERT_TRUE(ret);
+ tidl::CsStubGen gen(ps->GetDoc());
+ gen.Run("test_stub.cs");
+
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs", "namespace RPCPort"));
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs", " internal static partial class Stub"));
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs", " sealed class Student"));
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs", " public string name { get; set; }"));
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs", " sealed class Class"));
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs", " public List<Student> students { get; set; }"));
+}
#include <gtest/gtest.h>
#include <iostream>
+#include <memory>
#include "idlc/generator.h"
#include "idlc/interface.h"
: tidl::Generator(doc), count_(0) {}
~SampleGenerator() {}
- void OnInterfaceBegin(std::ofstream& stream,
- const std::string& id,
- const std::string& comments) override {
- interfaceID_ = id;
- count_++;
- }
- void OnInterfaceEnd(std::ofstream& stream, const std::string& id) override {
- count_++;
- }
- void OnDeclarationGen(std::ofstream& stream, const std::string& id,
- const tidl::Parameters& args,
- const tidl::BaseType& ret,
- const std::string& comments) override {
- count_++;
- }
- void OnStructureBegin(std::ofstream& stream,
- const std::string& id,
- const std::string& comments) override {
- structureID_ = id;
- count_++;
- }
- void OnStructureEnd(std::ofstream& stream, const std::string& id) override {
- count_++;
- }
- void OnElementGen(std::ofstream& stream, const std::string& id,
- const tidl::BaseType& type,
- const std::string& comments) override {
- count_++;
- }
void OnInitGen(std::ofstream& stream) override {
count_++;
}
count_++;
}
- const int GetCount() const {
+ int GetCount() {
return count_;
}
- const std::string& GetInterfaceID() const {
- return interfaceID_;
- }
+ private:
+ int count_;
+};
- const std::string& GetStructureID() const {
- return structureID_;
+class CodeBlockGenerator : public tidl::Generator {
+ public:
+ explicit CodeBlockGenerator(std::shared_ptr<tidl::Document> doc)
+ : tidl::Generator(doc) {}
+ ~CodeBlockGenerator() {}
+
+ void OnInitGen(std::ofstream& stream) override {
+ GenCodeBlock("cs_interop.cb",
+ [](Generator& gen, int pos) {
+ (static_cast<CodeBlockGenerator&>(gen)).touch = true;
+ ASSERT_TRUE(pos == 1);
+ });
}
+ void OnFiniGen(std::ofstream& stream) override {}
- private:
- int count_;
- std::string interfaceID_;
- std::string structureID_;
+ public:
+ bool touch = false;
};
class GeneratorTest : public testing::Test {
public:
- tidl::Document* doc;
+ SampleGenerator* gen;
+
+ virtual void SetUp() {
+ gen = new SampleGenerator(
+ std::shared_ptr<tidl::Document>(new tidl::Document()));
+ }
+ virtual void TearDown() {
+ delete gen;
+ }
+};
+
+class CodeBlockTest : public testing::Test {
+ public:
+ CodeBlockGenerator* gen;
virtual void SetUp() {
- tidl::Parameters* params = new tidl::Parameters();
- EXPECT_NE(params, nullptr);
- params->Add(new tidl::Parameter("test",
- new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__));
-
- tidl::Declaration* decl = new tidl::Declaration("test",
- new tidl::BaseType("int", ""), params, "", __LINE__);
- EXPECT_NE(decl, nullptr);
-
- tidl::Declarations* decls = new tidl::Declarations();
- EXPECT_NE(decls, nullptr);
- decls->Add(decl);
-
- tidl::Elements* elms = new tidl::Elements();
- EXPECT_NE(elms, nullptr);
- elms->Add(new tidl::Element("test", new tidl::BaseType("int", ""),
- "", __LINE__));
-
- doc = new tidl::Document();
- EXPECT_NE(doc, nullptr);
- doc->AddBlock(new tidl::Interface("TestInterface", decls, "", __LINE__));
- doc->AddBlock(new tidl::Structure("TestStructure", elms, "", __LINE__));
+ gen = new CodeBlockGenerator(
+ std::shared_ptr<tidl::Document>(new tidl::Document()));
+ }
+ virtual void TearDown() {
+ delete gen;
}
- virtual void TearDown() {}
};
TEST_F(GeneratorTest, Generator_Constructor) {
- std::shared_ptr<tidl::Document> docPtr(doc);
- SampleGenerator* sampleGen = new SampleGenerator(docPtr);
- EXPECT_NE(sampleGen, nullptr);
- delete sampleGen;
+ EXPECT_NE(gen, nullptr);
}
TEST_F(GeneratorTest, Generator_Run) {
- std::shared_ptr<tidl::Document> docPtr(doc);
- SampleGenerator* sampleGen = new SampleGenerator(docPtr);
- EXPECT_NE(sampleGen, nullptr);
- sampleGen->Run("test.txt");
- EXPECT_EQ(sampleGen->GetCount(), 8);
- EXPECT_EQ(sampleGen->GetInterfaceID(), "TestInterface");
- EXPECT_EQ(sampleGen->GetStructureID(), "TestStructure");
- delete sampleGen;
+ EXPECT_NE(gen, nullptr);
+ gen->Run("test.out");
+ EXPECT_TRUE(gen->GetCount() == 2);
+}
+
+TEST_F(CodeBlockTest, Generator_GenCodeBlock) {
+ EXPECT_NE(gen, nullptr);
+ gen->Run("test.out");
+ EXPECT_TRUE(gen->touch);
}
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-#include <gtest/gtest.h>
-
-#include <iostream>
-
-#include "idlc/proxy_gen.h"
-#include "idlc/interface.h"
-#include "idlc/structure.h"
-
-class ProxyGenTest : public testing::Test {
- public:
- tidl::Document* doc;
-
- virtual void SetUp() {
- tidl::Parameters* params = new tidl::Parameters();
- EXPECT_NE(params, nullptr);
- params->Add(new tidl::Parameter("test",
- new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__));
-
- tidl::Declaration* decl = new tidl::Declaration("test",
- new tidl::BaseType("int", ""), params, "", __LINE__);
- EXPECT_NE(decl, nullptr);
-
- tidl::Declarations* decls = new tidl::Declarations();
- EXPECT_NE(decls, nullptr);
- decls->Add(decl);
-
- tidl::Elements* elms = new tidl::Elements();
- EXPECT_NE(elms, nullptr);
- elms->Add(new tidl::Element("test", new tidl::BaseType("int", ""),
- "", __LINE__));
-
- doc = new tidl::Document();
- EXPECT_NE(doc, nullptr);
- doc->AddBlock(new tidl::Interface("TestInterface", decls, "", __LINE__));
- doc->AddBlock(new tidl::Structure("TestStructure", elms, "", __LINE__));
- }
- virtual void TearDown() {}
-
- bool IsExistence(const std::string& file) const {
- if (std::ifstream(file))
- return true;
-
- return false;
- }
-};
-
-TEST_F(ProxyGenTest, ProxyGen_Constructor) {
- std::shared_ptr<tidl::Document> docPtr(doc);
- tidl::ProxyGen* gen = new tidl::ProxyGen(docPtr);
- EXPECT_NE(gen, nullptr);
- delete gen;
-}
-
-TEST_F(ProxyGenTest, ProxyGen_Run) {
- std::shared_ptr<tidl::Document> docPtr(doc);
- tidl::ProxyGen* gen = new tidl::ProxyGen(docPtr);
- EXPECT_NE(gen, nullptr);
- gen->Run("ProxyGen.txt");
- EXPECT_EQ(IsExistence("ProxyGen.txt"), true);
- delete gen;
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-#include <gtest/gtest.h>
-
-#include <iostream>
-
-#include "idlc/stub_gen.h"
-#include "idlc/interface.h"
-#include "idlc/structure.h"
-
-class StubGenTest : public testing::Test {
- public:
- tidl::Document* doc;
-
- virtual void SetUp() {
- tidl::Parameters* params = new tidl::Parameters();
- EXPECT_NE(params, nullptr);
- params->Add(new tidl::Parameter("test",
- new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__));
-
- tidl::Declaration* decl = new tidl::Declaration("test",
- new tidl::BaseType("int", ""), params, "", __LINE__);
- EXPECT_NE(decl, nullptr);
-
- tidl::Declarations* decls = new tidl::Declarations();
- EXPECT_NE(decls, nullptr);
- decls->Add(decl);
-
- tidl::Elements* elms = new tidl::Elements();
- EXPECT_NE(elms, nullptr);
- elms->Add(new tidl::Element("test", new tidl::BaseType("int", ""),
- "", __LINE__));
-
- doc = new tidl::Document();
- EXPECT_NE(doc, nullptr);
- doc->AddBlock(new tidl::Interface("TestInterface", decls, "", __LINE__));
- doc->AddBlock(new tidl::Structure("TestStructure", elms, "", __LINE__));
- }
- virtual void TearDown() {}
-};
-
-TEST_F(StubGenTest, StubGen_Constructor) {
- std::shared_ptr<tidl::Document> docPtr(doc);
- tidl::StubGen* gen = new tidl::StubGen(docPtr);
- EXPECT_NE(gen, nullptr);
- delete gen;
-}
TEST_F(BaseTypeTest, BaseType_SetMetaType) {
tidl::BaseType* customType = new tidl::BaseType("CustomType", "", true);
customType->SetMetaType(new tidl::BaseType("int", ""));
- EXPECT_EQ(customType->GetMetaType().ToString(), "int");
+ EXPECT_EQ(customType->GetMetaType()->ToString(), "int");
delete customType;
}
TEST_F(BaseTypeTest, BaseType_GetMetaType) {
tidl::BaseType* customType = new tidl::BaseType("CustomType", "", true);
customType->SetMetaType(new tidl::BaseType("string", ""));
- EXPECT_EQ(customType->GetMetaType().ToString(), "string");
+ EXPECT_EQ(customType->GetMetaType()->ToString(), "string");
delete customType;
}