Skip to content

Commit

Permalink
Improve test for target, starting adding new code for targets and sou…
Browse files Browse the repository at this point in the history
…rces
  • Loading branch information
sgranjoux committed Dec 10, 2009
1 parent 18ae72f commit fbbb020
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 23 deletions.
61 changes: 45 additions & 16 deletions src/am-project.c
Original file line number Diff line number Diff line change
Expand Up @@ -1680,17 +1680,17 @@ amp_project_add_sibling_group (AmpProject *project,
if (g_hash_table_lookup (project->groups, uri) != NULL)
{
g_free (uri);
error_set (error, IANJUTA_PROJECT_ERROR_VALIDATION_FAILED,
_("Sibling group has not the same parent"));
error_set (error, IANJUTA_PROJECT_ERROR_DOESNT_EXIST,
_("Group already exists"));
return NULL;
}

/* If a sibling is used, check that the parent is right */
if ((sibling != NULL) && (parent != anjuta_project_node_parent (sibling)))
{
g_free (uri);
error_set (error, IANJUTA_PROJECT_ERROR_DOESNT_EXIST,
_("Group already exists"));
error_set (error, IANJUTA_PROJECT_ERROR_VALIDATION_FAILED,
_("Sibling group has not the same parent"));
return NULL;
}

Expand Down Expand Up @@ -1883,12 +1883,8 @@ amp_project_remove_group (AmpProject *project,
amp_group_free (group);
}

AmpTarget*
amp_project_add_target (AmpProject *project,
AmpGroup *parent,
const gchar *name,
AnjutaProjectTargetType type,
GError **error)
AmpGroup*
amp_project_add_sibling_target (AmpProject *project, AmpGroup *parent, const gchar *name, AnjutaProjectTargetType type, gboolean after, AmpGroup *sibling, GError **error)
{
AmpTarget *child;
AnjutaToken* token;
Expand Down Expand Up @@ -1941,6 +1937,14 @@ amp_project_add_target (AmpProject *project,
return NULL;
}
}

/* If a sibling is used, check that the parent is right */
if ((sibling != NULL) && (parent != anjuta_project_node_parent (sibling)))
{
error_set (error, IANJUTA_PROJECT_ERROR_VALIDATION_FAILED,
_("Sibling target has not the same parent"));
return NULL;
}

/* Check that the new target doesn't already exist */
find = (gchar *)name;
Expand All @@ -1955,7 +1959,15 @@ amp_project_add_target (AmpProject *project,

/* Add target node in project tree */
child = amp_target_new (name, type, "", 0);
anjuta_project_node_append (parent, child);
if (after)
{
anjuta_project_node_insert_after (parent, sibling, child);
}
else
{
anjuta_project_node_insert_before (parent, sibling, child);
}
//anjuta_project_node_append (parent, child);

/* Add in Makefile.am */
targetname = g_strconcat (((AmpTargetInformation *)type)->install, ((AmpTargetInformation *)type)->prefix, NULL);
Expand Down Expand Up @@ -2037,6 +2049,16 @@ amp_project_add_target (AmpProject *project,
return child;
}

AmpTarget*
amp_project_add_target (AmpProject *project,
AmpGroup *parent,
const gchar *name,
AnjutaProjectTargetType type,
GError **error)
{
return amp_project_add_sibling_target (project, parent, name, type, TRUE, NULL, error);
}

void
amp_project_remove_target (AmpProject *project,
AmpTarget *target,
Expand All @@ -2054,11 +2076,8 @@ amp_project_remove_target (AmpProject *project,
amp_target_free (target);
}

AmpSource*
amp_project_add_source (AmpProject *project,
AmpTarget *target,
GFile *file,
GError **error)
AmpGroup*
amp_project_add_sibling_source (AmpProject *project, AmpTarget *target, GFile *file, gboolean after, AmpGroup *sibling, GError **error)
{
AmpGroup *group;
AmpSource *last;
Expand Down Expand Up @@ -2124,6 +2143,16 @@ amp_project_add_source (AmpProject *project,
return source;
}


AmpSource*
amp_project_add_source (AmpProject *project,
AmpTarget *target,
GFile *file,
GError **error)
{
return amp_project_add_sibling_source (project, target, file, TRUE, NULL, error);
}

void
amp_project_remove_source (AmpProject *project,
AmpSource *source,
Expand Down
2 changes: 2 additions & 0 deletions src/am-project.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ AmpGroup* amp_project_add_sibling_group (AmpProject *project, AmpGroup *parent,
void amp_project_remove_group (AmpProject *project, AmpGroup *group, GError **error);

AmpTarget* amp_project_add_target (AmpProject *project, AmpGroup *parent, const gchar *name, AnjutaProjectTargetType type, GError **error);
AmpGroup* amp_project_add_sibling_target (AmpProject *project, AmpGroup *parent, const gchar *name, AnjutaProjectTargetType type, gboolean after, AmpGroup *sibling, GError **error);
void amp_project_remove_target (AmpProject *project, AmpTarget *target, GError **error);

AmpSource* amp_project_add_source (AmpProject *project, AmpTarget *parent, GFile *file, GError **error);
AmpGroup* amp_project_add_sibling_source (AmpProject *project, AmpTarget *parent, GFile *file, gboolean after, AmpGroup *sibling, GError **error);
void amp_project_remove_source (AmpProject *project, AmpSource *source, GError **error);


Expand Down
37 changes: 33 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,44 @@ main(int argc, char *argv[])
}
else if (g_ascii_strcasecmp (command[1], "target") == 0)
{

ianjuta_project_add_target (project, node, command[3], get_type (project, command[4]), NULL);
if ((command[5] != NULL) && (g_ascii_strcasecmp (command[5], "before") == 0))
{
sibling = get_node (project, command[6]);
amp_project_add_sibling_target (project, node, command[3], get_type (project, command[4]), FALSE, sibling, NULL);
command += 2;
}
else if ((command[5] != NULL) && (g_ascii_strcasecmp (command[5], "after") == 0))
{
sibling = get_node (project, command[6]);
amp_project_add_sibling_target (project, node, command[3], get_type (project, command[4]), TRUE, sibling, NULL);
command += 2;
}
else
{
ianjuta_project_add_target (project, node, command[3], get_type (project, command[4]), NULL);
}
command++;
}
else if (g_ascii_strcasecmp (command[1], "source") == 0)
{
GFile *file = get_file (node, command[3]);

ianjuta_project_add_source (project, node, file, NULL);

if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "before") == 0))
{
sibling = get_file (project, command[5]);
amp_project_add_sibling_source (project, node, file, FALSE, sibling, NULL);
command += 2;
}
else if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "after") == 0))
{
sibling = get_node (project, command[5]);
amp_project_add_sibling_source (project, node, file, TRUE, sibling, NULL);
command += 2;
}
else
{
ianjuta_project_add_source (project, node, file, NULL);
}
g_object_unref (file);
}
else
Expand Down
20 changes: 17 additions & 3 deletions tests/target.at
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,30 @@ AT_DATA([empty/Makefile.am],
[[
]])
AT_DATA([expect],
[[ GROUP (0): empty3
[[ GROUP (0): empty1
TARGET (0:0): target1
]])
AT_PARSER_CHECK([load empty \
move empty3 \
move empty1 \
add target 0 target1 1 \
list \
save])
AT_CHECK([diff output expect])
AT_PARSER_CHECK([load empty3 \
AT_PARSER_CHECK([load empty1 \
list])
AT_CHECK([diff output expect])
AT_DATA([expect],
[[ GROUP (0): empty2
TARGET (0:0): target1
TARGET (0:1): target2
]])
AT_PARSER_CHECK([load empty1 \
move empty2 \
add target 0 target2 1 after 0:0\
list \
save])
AT_CHECK([diff -b output expect])
AT_PARSER_CHECK([load empty2 \
list])
AT_CHECK([diff -b output expect])
AT_CLEANUP

0 comments on commit fbbb020

Please sign in to comment.