Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java.Interop.Tools.JavaCallableWrappers-Tests] Add unit tests. #40

Merged
merged 1 commit into from
May 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Java.Interop.sln
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Java.Interop.Tools.TypeName
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "jcw-gen", "tools\jcw-gen\jcw-gen.csproj", "{52C7D9B6-E8C8-47D0-9471-652D278D7D77}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Tools.JavaCallableWrappers-Tests.csproj", "src\Java.Interop.Tools.JavaCallableWrappers\Test\Java.Interop.Tools.JavaCallableWrappers-Tests.csproj", "{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -303,6 +305,14 @@ Global
{D14A1B5C-2060-4930-92BE-F7190256C735}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU
{D14A1B5C-2060-4930-92BE-F7190256C735}.XAIntegrationRelease|Any CPU.ActiveCfg = Release|Any CPU
{D14A1B5C-2060-4930-92BE-F7190256C735}.XAIntegrationRelease|Any CPU.Build.0 = Release|Any CPU
{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F}.Release|Any CPU.Build.0 = Release|Any CPU
{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F}.XAIntegrationDebug|Any CPU.ActiveCfg = Debug|Any CPU
{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU
{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F}.XAIntegrationRelease|Any CPU.ActiveCfg = Release|Any CPU
{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F}.XAIntegrationRelease|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{0C001D50-4176-45AE-BDC8-BA626508B0CC} = {C8F58966-94BF-407F-914A-8654F8B8AE3B}
Expand Down Expand Up @@ -342,5 +352,6 @@ Global
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
{E706B6F2-5562-4765-8F07-8CF84A797B30} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
{52C7D9B6-E8C8-47D0-9471-652D278D7D77} = {C8F58966-94BF-407F-914A-8654F8B8AE3B}
{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F} = {271C9F30-F679-4793-942B-0D9527CB3E2F}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ TESTS = \
bin/Test$(CONFIGURATION)/Java.Interop-Tests.dll \
bin/Test$(CONFIGURATION)/Java.Interop.Dynamic-Tests.dll \
bin/Test$(CONFIGURATION)/Java.Interop.Export-Tests.dll \
bin/Test$(CONFIGURATION)/Java.Interop.Tools.JavaCallableWrappers-Tests.dll \
bin/Test$(CONFIGURATION)/LogcatParse-Tests.dll \
bin/Test$(CONFIGURATION)/generator-Tests.dll \
bin/Test$(CONFIGURATION)/Xamarin.Android.Tools.ApiXmlAdjuster-Tests.dll \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void AddNestedTypes (TypeDefinition type)
this.type = type;
this.log = log;

if (!type.IsClass)
if (type.IsEnum || type.IsInterface || type.IsValueType)
Diagnostic.Error (4200, LookupSource (type), "Can only generate Java wrappers for 'class' types, not type '{0}'.", type.FullName);

string jniName = JniType.ToJniName (type);
Expand Down Expand Up @@ -431,42 +431,47 @@ static string GetJniSignature (MethodDefinition ctor)
// private native void n_onCreate (android.os.Bundle bundle);
// }

public void Generate (string outputPath)
public void Generate (TextWriter writer)
{
using (StreamWriter sw = OpenStream (outputPath)) {
if (!string.IsNullOrEmpty (package)) {
sw.WriteLine ("package " + package + ";");
sw.WriteLine ();
}
if (!string.IsNullOrEmpty (package)) {
writer.WriteLine ("package " + package + ";");
writer.WriteLine ();
}

GenerateHeader (sw);
GenerateHeader (writer);

sw.WriteLine ("/** @hide */");
sw.WriteLine ("\tpublic static final String __md_methods;");
if (children != null) {
foreach (var i in Enumerable.Range(1, children.Count))
sw.WriteLine ("\tstatic final String __md_{0}_methods;", i);
}
sw.WriteLine ("\tstatic {");
GenerateRegisterType (sw, this, "__md_methods");
if (children != null) {
for (int i = 0; i < children.Count; ++i) {
string methods = string.Format ("__md_{0}_methods", i+1);
GenerateRegisterType (sw, children [i], methods);
}
writer.WriteLine ("/** @hide */");
writer.WriteLine ("\tpublic static final String __md_methods;");
if (children != null) {
foreach (var i in Enumerable.Range (1, children.Count))
writer.WriteLine ("\tstatic final String __md_{0}_methods;", i);
}
writer.WriteLine ("\tstatic {");
GenerateRegisterType (writer, this, "__md_methods");
if (children != null) {
for (int i = 0; i < children.Count; ++i) {
string methods = string.Format ("__md_{0}_methods", i + 1);
GenerateRegisterType (writer, children [i], methods);
}
sw.WriteLine ("\t}");
}
writer.WriteLine ("\t}");

GenerateBody (sw);
GenerateBody (writer);

if (children != null)
foreach (JavaCallableWrapperGenerator child in children) {
child.GenerateHeader (sw);
child.GenerateBody (sw);
child.GenerateFooter (sw);
}
if (children != null)
foreach (JavaCallableWrapperGenerator child in children) {
child.GenerateHeader (writer);
child.GenerateBody (writer);
child.GenerateFooter (writer);
}

GenerateFooter (writer);
}

GenerateFooter (sw);
public void Generate (string outputPath)
{
using (StreamWriter sw = OpenStream (outputPath)) {
Generate (sw);
}
}

Expand Down Expand Up @@ -515,7 +520,7 @@ static string ManagedValueToJavaSource (object value)
return value.ToString ();
}

void GenerateHeader (StreamWriter sw)
void GenerateHeader (TextWriter sw)
{
sw.WriteLine ();

Expand All @@ -541,7 +546,7 @@ void GenerateHeader (StreamWriter sw)
sw.WriteLine ("{");
}

void GenerateBody (StreamWriter sw)
void GenerateBody (TextWriter sw)
{
foreach (Signature ctor in ctors) {
if (string.IsNullOrEmpty (ctor.Params) && JniType.IsApplication (type))
Expand Down Expand Up @@ -584,7 +589,7 @@ void GenerateBody (StreamWriter sw)
sw.WriteLine ("\t}");
}

static void GenerateRegisterType (StreamWriter sw, JavaCallableWrapperGenerator self, string field)
static void GenerateRegisterType (TextWriter sw, JavaCallableWrapperGenerator self, string field)
{
sw.WriteLine ("\t\t{0} = ", field);
foreach (Signature method in self.methods)
Expand All @@ -595,7 +600,7 @@ static void GenerateRegisterType (StreamWriter sw, JavaCallableWrapperGenerator
self.type.GetAssemblyQualifiedName (), self.name, field);
}

void GenerateFooter (StreamWriter sw)
void GenerateFooter (TextWriter sw)
{
sw.WriteLine ("}");
}
Expand Down Expand Up @@ -738,7 +743,7 @@ public string Retval {
public readonly string Annotations;
}

void GenerateConstructor (Signature ctor, StreamWriter sw)
void GenerateConstructor (Signature ctor, TextWriter sw)
{
// TODO: we only generate constructors so that Android types w/ no
// default constructor can be subclasses by our generated code.
Expand All @@ -760,7 +765,7 @@ void GenerateConstructor (Signature ctor, StreamWriter sw)
sw.WriteLine ("\t}");
}

void GenerateApplicationConstructor (StreamWriter sw)
void GenerateApplicationConstructor (TextWriter sw)
{
if (!JniType.IsApplication (type)) {
return;
Expand All @@ -773,15 +778,15 @@ void GenerateApplicationConstructor (StreamWriter sw)
sw.WriteLine ("\t}");
}

void GenerateExportedField (JavaFieldInfo field, StreamWriter sw)
void GenerateExportedField (JavaFieldInfo field, TextWriter sw)
{
sw.WriteLine ();
if (field.Annotations != null)
sw.WriteLine (field.Annotations);
sw.WriteLine ("\t{0} {1}{2} {3} = {4} ();", field.GetJavaAccess (), field.IsStatic ? "static " : null, field.TypeName, field.FieldName, field.InitializerName);
}

void GenerateMethod (Signature method, StreamWriter sw)
void GenerateMethod (Signature method, TextWriter sw)
{
sw.WriteLine ();
if (method.Annotations != null)
Expand All @@ -798,7 +803,7 @@ void GenerateMethod (Signature method, StreamWriter sw)
sw.WriteLine ("\tprivate {0}native {1} n_{2} ({3});", method.IsStatic ? "static " : null, method.Retval, method.Name, method.Params);
}

void WriteApplicationOnCreate (StreamWriter sw, Action<StreamWriter> extra)
void WriteApplicationOnCreate (TextWriter sw, Action<TextWriter> extra)
{
sw.WriteLine ();
sw.WriteLine ("\tpublic void onCreate ()");
Expand All @@ -807,7 +812,7 @@ void WriteApplicationOnCreate (StreamWriter sw, Action<StreamWriter> extra)
sw.WriteLine ("\t}");
}

void WriteInstrumentationOnCreate (StreamWriter sw, Action<StreamWriter> extra)
void WriteInstrumentationOnCreate (TextWriter sw, Action<TextWriter> extra)
{
sw.WriteLine ();
sw.WriteLine ("\tpublic void onCreate (android.os.Bundle arguments)");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Java.Interop.Tools.JavaCallableWrappersTests</RootNamespace>
<AssemblyName>Java.Interop.Tools.JavaCallableWrappers-Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\bin\TestDebug</OutputPath>
<DefineConstants>DEBUG;JCW_ONLY_TYPE_NAMES</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>..\..\..\bin\TestRelease</OutputPath>
<DefineConstants>JCW_ONLY_TYPE_NAMES</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="nunit.framework">
<HintPath>..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil">
<HintPath>..\..\..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Mdb">
<HintPath>..\..\..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Pdb">
<HintPath>..\..\..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Rocks">
<HintPath>..\..\..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Java.Interop.Tools.JavaCallableWrappers\JavaCallableWrapperGeneratorTests.cs" />
<Compile Include="Java.Interop.Tools.JavaCallableWrappers\TypeNameMapGeneratorTests.cs" />
<Compile Include="Java.Interop.Tools.JavaCallableWrappers\SupportDeclarations.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\jcw-gen.csproj">
<Project>{52C7D9B6-E8C8-47D0-9471-652D278D7D77}</Project>
<Name>jcw-gen</Name>
</ProjectReference>
<ProjectReference Include="..\Java.Interop.Tools.JavaCallableWrappers.csproj">
<Project>{D18FCF91-8876-48A0-A693-2DC1E7D3D80A}</Project>
<Name>Java.Interop.Tools.JavaCallableWrappers</Name>
</ProjectReference>
<ProjectReference Include="..\..\Java.Interop.Tools.Cecil\Java.Interop.Tools.Cecil.csproj">
<Project>{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}</Project>
<Name>Java.Interop.Tools.Cecil</Name>
</ProjectReference>
<ProjectReference Include="..\..\Java.Interop.Tools.Diagnostics\Java.Interop.Tools.Diagnostics.csproj">
<Project>{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}</Project>
<Name>Java.Interop.Tools.Diagnostics</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Java.Interop.Tools.JavaCallableWrappers\" />
</ItemGroup>
<Import Project="..\..\Xamarin.Android.NamingCustomAttributes\Xamarin.Android.NamingCustomAttributes.projitems" Label="Shared" Condition="Exists('..\..\Xamarin.Android.NamingCustomAttributes\Xamarin.Android.NamingCustomAttributes.projitems')" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
Loading