using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; using Tensorflow; namespace TensorFlowNET.UnitTest { /// /// tensorflow\c\c_api_test.cc /// `class CApiAttributesTest` /// [TestClass] public class CApiAttributesTestcs : CApiTest, IDisposable { private Graph graph_; private int counter_; private Status s_; public CApiAttributesTestcs() { s_ = new Status(); graph_ = new Graph(); } private OperationDescription init(string type) { // Construct op_name to match the name used by REGISTER_OP in the // ATTR_TEST_REGISTER calls above. string op_name = "CApiAttributesTestOp"; if (type.Contains("list(")) { op_name += "List"; type = type.Substring(5, type.Length - 6); } op_name += type; return c_api.TF_NewOperation(graph_, op_name, $"name{counter_++}"); } /// /// REGISTER_OP for CApiAttributesTest test cases. /// Registers two ops, each with a single attribute called 'v'. /// The attribute in one op will have a type 'type', the other /// will have list(type). /// /// private void ATTR_TEST_REGISTER_OP(string type) { } private void EXPECT_TF_META(Operation oper, string attr_name, int expected_list_size, TF_AttrType expected_type, uint expected_total_size) { var m = c_api.TF_OperationGetAttrMetadata(oper, attr_name, s_); EXPECT_EQ(TF_Code.TF_OK, s_.Code); char e = expected_list_size >= 0 ? (char)1 : (char)0; /*EXPECT_EQ(e, m.is_list); EXPECT_EQ(expected_list_size, m.list_size); EXPECT_EQ(expected_type, m.type); EXPECT_EQ(expected_total_size, m.total_size);*/ } [TestMethod] public void String() { var desc = init("string"); var handle = Marshal.StringToHGlobalAnsi("bunny"); c_api.TF_SetAttrString(desc, "v", handle, 5); //var oper = c_api.TF_FinishOperation(desc, s_); //ASSERT_EQ(TF_Code.TF_OK, s_.Code); //EXPECT_TF_META(oper, "v", -1, TF_AttrType.TF_ATTR_STRING, 5); //var value = new char[5]; //c_api.TF_OperationGetAttrString(oper, "v", value, 5, s_); //EXPECT_EQ(TF_Code.TF_OK, s_.Code); //EXPECT_EQ("bunny", value, 5)); } public void Dispose() { graph_.Dispose(); s_.Dispose(); } } }