Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Refactor writer (#43)
Browse files Browse the repository at this point in the history
* Refactor more writer code to make for shorter code

* Move GtkAboutDialog test to class

* Move writer header call to GetWriter

* Refactor a bit

* Don't expose repository from options

* Add a way to add in custom generatables and fix class inheritance

* Add varags so GObject can be generated

* Properly generate object class

* Add important generatables folder and generate list too

* Fixup tests
  • Loading branch information
Therzok authored Mar 3, 2018
1 parent f355bc3 commit 69814a7
Show file tree
Hide file tree
Showing 33 changed files with 801 additions and 271 deletions.
8 changes: 6 additions & 2 deletions src/Gir.Tests/BitFieldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public class BitFieldTests : GenerationTestBase
public void GenerateDocumentationWhenCompatFalse ()
{
var result = GenerateType (Pango, "FontMask");
Assert.AreEqual (@"namespace Pango
Assert.AreEqual (@"using System;
namespace Pango
{
///<summary>
/// The bits in a #PangoFontMask correspond to fields in a
Expand Down Expand Up @@ -49,7 +51,9 @@ public void GenerateNoDocumentationWhenCompatTrue ()
{
var result = GenerateType (Pango, "FontMask", compat: true);

Assert.AreEqual (@"namespace Pango
Assert.AreEqual (@"using System;
namespace Pango
{
[Flags]
public enum FontMask
Expand Down
4 changes: 3 additions & 1 deletion src/Gir.Tests/CallbackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public void TestCallbackIsGenerated ()
{
var result = GenerateType (Gtk3, "TreeModelFilterModifyFunc");

Assert.AreEqual (@"namespace Gtk
Assert.AreEqual (@"using System;
namespace Gtk
{
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
public delegate void TreeModelFilterModifyFunc (ITreeModel model, TreeIter iter, Value value, int column, IntPtr data)
Expand Down
156 changes: 155 additions & 1 deletion src/Gir.Tests/ClassTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public void TestClassIsGenerated ()
var result = GenerateType (Gio2, "BufferedOutputStream");

// Need to map pointers at symbol level.
Assert.AreEqual (@"namespace Gio
Assert.AreEqual (@"using System;
namespace Gio
{
///<summary>
/// Buffered output stream implements #GFilterOutputStream and provides
Expand Down Expand Up @@ -86,5 +88,157 @@ public BufferedOutputStream (OutputStream base_stream, UIntPtr size) : base (bas
}
", result);
}

[Test]
public void GenerateGtkAboutDialog ()
{
var result = GenerateType(Gtk3, "AboutDialog", true);

Assert.AreEqual (@"using System;
namespace Gtk
{
public class AboutDialog : Dialog, Atk.ImplementorIface, Buildable
{
static extern Widget gtk_about_dialog_new ();
public AboutDialog () : base ()
{
}
Dialog ParentInstance;
AboutDialogPrivate Priv;
static extern void gtk_about_dialog_add_credit_section (AboutDialog about, string section_name, string people);
public void AddCreditSection (string section_name, string people);
static extern string gtk_about_dialog_get_artists (AboutDialog about);
public string GetArtists ();
static extern string gtk_about_dialog_get_authors (AboutDialog about);
public string GetAuthors ();
static extern string gtk_about_dialog_get_comments (AboutDialog about);
public string GetComments ();
static extern string gtk_about_dialog_get_copyright (AboutDialog about);
public string GetCopyright ();
static extern string gtk_about_dialog_get_documenters (AboutDialog about);
public string GetDocumenters ();
static extern string gtk_about_dialog_get_license (AboutDialog about);
public string GetLicense ();
static extern License gtk_about_dialog_get_license_type (AboutDialog about);
public License GetLicenseType ();
static extern Pixbuf gtk_about_dialog_get_logo (AboutDialog about);
public Pixbuf GetLogo ();
static extern string gtk_about_dialog_get_logo_icon_name (AboutDialog about);
public string GetLogoIconName ();
static extern string gtk_about_dialog_get_program_name (AboutDialog about);
public string GetProgramName ();
static extern string gtk_about_dialog_get_translator_credits (AboutDialog about);
public string GetTranslatorCredits ();
static extern string gtk_about_dialog_get_version (AboutDialog about);
public string GetVersion ();
static extern string gtk_about_dialog_get_website (AboutDialog about);
public string GetWebsite ();
static extern string gtk_about_dialog_get_website_label (AboutDialog about);
public string GetWebsiteLabel ();
static extern bool gtk_about_dialog_get_wrap_license (AboutDialog about);
public bool GetWrapLicense ();
static extern void gtk_about_dialog_set_artists (AboutDialog about, string artists);
public void SetArtists (string artists);
static extern void gtk_about_dialog_set_authors (AboutDialog about, string authors);
public void SetAuthors (string authors);
static extern void gtk_about_dialog_set_comments (AboutDialog about, string comments);
public void SetComments (string comments);
static extern void gtk_about_dialog_set_copyright (AboutDialog about, string copyright);
public void SetCopyright (string copyright);
static extern void gtk_about_dialog_set_documenters (AboutDialog about, string documenters);
public void SetDocumenters (string documenters);
static extern void gtk_about_dialog_set_license (AboutDialog about, string license);
public void SetLicense (string license);
static extern void gtk_about_dialog_set_license_type (AboutDialog about, License license_type);
public void SetLicenseType (License license_type);
static extern void gtk_about_dialog_set_logo (AboutDialog about, Pixbuf logo);
public void SetLogo (Pixbuf logo);
static extern void gtk_about_dialog_set_logo_icon_name (AboutDialog about, string icon_name);
public void SetLogoIconName (string icon_name);
static extern void gtk_about_dialog_set_program_name (AboutDialog about, string name);
public void SetProgramName (string name);
static extern void gtk_about_dialog_set_translator_credits (AboutDialog about, string translator_credits);
public void SetTranslatorCredits (string translator_credits);
static extern void gtk_about_dialog_set_version (AboutDialog about, string version);
public void SetVersion (string version);
static extern void gtk_about_dialog_set_website (AboutDialog about, string website);
public void SetWebsite (string website);
static extern void gtk_about_dialog_set_website_label (AboutDialog about, string website_label);
public void SetWebsiteLabel (string website_label);
static extern void gtk_about_dialog_set_wrap_license (AboutDialog about, bool wrap_license);
public void SetWrapLicense (bool wrap_license);
event AboutDialog.activate-linkHandler ActivateLink;
}
}
",
result);
}
}
}
4 changes: 3 additions & 1 deletion src/Gir.Tests/EnumerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public void PangoAlignmentIsGenerated ()
{
var result = GenerateType (Pango, "Alignment");

Assert.AreEqual (@"namespace Pango
Assert.AreEqual (@"using System;
namespace Pango
{
///<summary>
/// A #PangoAlignment describes how to align the lines of a #PangoLayout within the
Expand Down
8 changes: 6 additions & 2 deletions src/Gir.Tests/GenerationOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public void GenerateDocumentationWhenCompatFalse ()
{
var result = GenerateType (Pango, "Alignment");

Assert.AreEqual (@"namespace Pango
Assert.AreEqual (@"using System;
namespace Pango
{
///<summary>
/// A #PangoAlignment describes how to align the lines of a #PangoLayout within the
Expand All @@ -38,7 +40,9 @@ public void GenerateNoDocumentationWhenCompatTrue ()
{
var result = GenerateType (Pango, "Alignment", compat: true);

Assert.AreEqual (@"namespace Pango
Assert.AreEqual (@"using System;
namespace Pango
{
public enum Alignment
{
Expand Down
11 changes: 8 additions & 3 deletions src/Gir.Tests/GenerationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public abstract class GenerationTestBase
protected const string Gdk3 = "Gdk-3.0";
protected const string GLib = "GLib-2.0";
protected const string Gtk3 = "Gtk-3.0";
protected const string GObject = "GObject-2.0";
protected const string Pango = "Pango-1.0";
protected const string Gio2 = "Gio-2.0";
protected const string Atk1 = "Atk-1.0";
Expand Down Expand Up @@ -66,9 +67,13 @@ protected static string GetGenerationResult (GenerationOptions opts)
return Encoding.UTF8.GetString (ms.ToArray ());
}

protected static GenerationOptions GetOptions (IEnumerable<Repository> repositories, Repository mainRepository, bool compat = false)
protected static GenerationOptions GetOptions (IEnumerable<Repository> repositories, Repository mainRepository, bool compat = false, bool generateMember = false)
{
return new GenerationOptions ("", repositories, mainRepository, compat, new MemoryStream ());
return new GenerationOptions ("", repositories, mainRepository, new GenerationOptions.ToggleOptions {
Compat = compat,
RedirectStream = new MemoryStream (),
WriteHeader = !generateMember,
});
}

protected static void GenerateType (Repository repo, GenerationOptions opts, string typeName)
Expand Down Expand Up @@ -98,7 +103,7 @@ protected static string GenerateType (string girFile, string typeName, bool comp
protected static string GenerateMember (string girFile, string typeName, string memberName, bool compat = false)
{
var repositories = ParseGirFile (girFile, out var mainRepository);
var opts = GetOptions (repositories, mainRepository, compat);
var opts = GetOptions (repositories, mainRepository, compat, generateMember: true);

GenerateMember (mainRepository, opts, typeName, memberName);

Expand Down
3 changes: 3 additions & 0 deletions src/Gir.Tests/Gir.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@
<Compile Include="ClassTests.cs" />
<Compile Include="InterfaceTests.cs" />
<Compile Include="CallbackTests.cs" />
<Compile Include="ImportantGeneratables\GObject.cs" />
<Compile Include="ImportantGeneratables\List.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="TestFiles\" />
<Folder Include="ImportantGeneratables\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="TestFiles\Atk-1.0.gir">
Expand Down
Loading

0 comments on commit 69814a7

Please sign in to comment.