Skip to content

Commit

Permalink
Merge pull request #366 from natural-law/master
Browse files Browse the repository at this point in the history
fixed #574
  • Loading branch information
minggo committed Jul 8, 2011
2 parents 2e7dfd9 + 8b357e0 commit eab0802
Show file tree
Hide file tree
Showing 35 changed files with 1,398 additions and 11 deletions.
Binary file added tests/Res/Default.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/bugs/RetinaDisplay.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/bugs/bug886.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/bugs/bug886.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/bugs/corner.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/bugs/edge.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/bugs/fill.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 108 additions & 0 deletions tests/test.win32/test.win32.vcproj
Expand Up @@ -963,6 +963,114 @@
>
</File>
</Filter>
<Filter
Name="DirectorTest"
>
<File
RelativePath="..\tests\DirectorTest\DirectorTest.cpp"
>
</File>
<File
RelativePath="..\tests\DirectorTest\DirectorTest.h"
>
</File>
</Filter>
<Filter
Name="BugsTest"
>
<File
RelativePath="..\tests\BugsTest\Bug-1159.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-1159.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-1174.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-1174.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-350.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-350.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-422.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-422.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-624.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-624.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-886.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-886.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-899.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-899.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-914.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-914.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\BugsTest.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\BugsTest.h"
>
</File>
<Filter
Name="Bug-458"
>
<File
RelativePath="..\tests\BugsTest\Bug-458\Bug-458.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-458\Bug-458.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-458\QuestionContainerSprite.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-458\QuestionContainerSprite.h"
>
</File>
</Filter>
</Filter>
</Filter>
</Filter>
</Files>
Expand Down
61 changes: 61 additions & 0 deletions tests/tests/BugsTest/Bug-1159.cpp
@@ -0,0 +1,61 @@
//
// Bug-1159.m
// Z-Fighting in iPad 2
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=1159
//
// Created by Greg Woods on 4/5/11.
// Copyright 2011 Westlake Design. All rights reserved.
//

#include "Bug-1159.h"

CCScene* Bug1159Layer::scene()
{
CCScene *pScene = CCScene::node();
Bug1159Layer* layer = Bug1159Layer::node();
pScene->addChild(layer);

return pScene;
}

bool Bug1159Layer::init()
{
if (BugsTestBaseLayer::init())
{
CCSize s = CCDirector::sharedDirector()->getWinSize();

CCLayerColor *background = CCLayerColor::layerWithColor(ccc4(255, 0, 255, 255));
addChild(background);

CCLayerColor *sprite_a = CCLayerColor::layerWithColorWidthHeight(ccc4(255, 0, 0, 255), 700, 700);
sprite_a->setAnchorPoint(ccp(0.5f, 0.5f));
sprite_a->setIsRelativeAnchorPoint(true);
sprite_a->setPosition(ccp(0.0, s.height/2));
addChild(sprite_a);

sprite_a->runAction(CCRepeatForever::actionWithAction((CCActionInterval*) CCSequence::actions(
CCMoveTo::actionWithDuration(1.0f, ccp(1024.0, 384.0)),
CCMoveTo::actionWithDuration(1.0f, ccp(0.0, 384.0)),
NULL)));

CCLayerColor *sprite_b = CCLayerColor::layerWithColorWidthHeight(ccc4(0, 0, 255, 255), 400, 400);
sprite_b->setAnchorPoint(ccp(0.5f, 0.5f));
sprite_b->setIsRelativeAnchorPoint(true);
sprite_b->setPosition(ccp(s.width/2, s.height/2));
addChild(sprite_b);

CCMenuItemLabel *label = CCMenuItemLabel::itemWithLabel(CCLabelTTF::labelWithString("Flip Me", "Helvetica", 24), this, menu_selector(Bug1159Layer::callBack));
CCMenu *menu = CCMenu::menuWithItems(label, NULL);
menu->setPosition(ccp(s.width - 200, 50.0));
addChild(menu);

return true;
}

return false;
}

void Bug1159Layer::callBack(CCObject* pSender)
{
CCDirector::sharedDirector()->replaceScene(CCTransitionPageTurn::transitionWithDuration(1.0f, Bug1159Layer::scene(), false));
}
16 changes: 16 additions & 0 deletions tests/tests/BugsTest/Bug-1159.h
@@ -0,0 +1,16 @@
#ifndef __BUG_1159_H__
#define __BUG_1159_H__

#include "BugsTest.h"

class Bug1159Layer : public BugsTestBaseLayer
{
public:
virtual bool init();
static CCScene* scene();
void callBack(CCObject* pSender);

LAYER_NODE_FUNC(Bug1159Layer);
};

#endif // __BUG_1159_H__
159 changes: 159 additions & 0 deletions tests/tests/BugsTest/Bug-1174.cpp
@@ -0,0 +1,159 @@
//
// Bug-1174
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=1174
//

#include "Bug-1174.h"

int check_for_error( CCPoint p1, CCPoint p2, CCPoint p3, CCPoint p4, float s, float t )
{
// the hit point is p3 + t * (p4 - p3);
// the hit point also is p1 + s * (p2 - p1);

CCPoint p4_p3 = ccpSub( p4, p3);
CCPoint p4_p3_t = ccpMult(p4_p3, t);
CCPoint hitPoint1 = ccpAdd( p3, p4_p3_t);

CCPoint p2_p1 = ccpSub( p2, p1);
CCPoint p2_p1_s = ccpMult(p2_p1, s);
CCPoint hitPoint2 = ccpAdd( p1, p2_p1_s);

// Since float has rounding errors, only check if diff is < 0.05
if( (fabs( hitPoint1.x - hitPoint2.x) > 0.1f) || ( fabs(hitPoint1.y - hitPoint2.y) > 0.1f) )
{
CCLog("ERROR: (%f,%f) != (%f,%f)", hitPoint1.x, hitPoint1.y, hitPoint2.x, hitPoint2.y);
return 1;
}

return 0;
}

bool Bug1174Layer::init()
{
if (BugsTestBaseLayer::init())
{
// // seed
// srand(0);

CCPoint A,B,C,D,p1,p2,p3,p4;
float s,t;

int err=0;
int ok=0;

//
// Test 1.
//
CCLog("Test1 - Start");
for( int i=0; i < 10000; i++)
{
// A | b
// -----
// c | d
float ax = CCRANDOM_0_1() * -5000;
float ay = CCRANDOM_0_1() * 5000;

// a | b
// -----
// c | D
float dx = CCRANDOM_0_1() * 5000;
float dy = CCRANDOM_0_1() * -5000;

// a | B
// -----
// c | d
float bx = CCRANDOM_0_1() * 5000;
float by = CCRANDOM_0_1() * 5000;

// a | b
// -----
// C | d
float cx = CCRANDOM_0_1() * -5000;
float cy = CCRANDOM_0_1() * -5000;

A = ccp(ax,ay);
B = ccp(bx,by);
C = ccp(cx,cy);
D = ccp(dx,dy);
if( ccpLineIntersect( A, D, B, C, &s, &t) ) {
if( check_for_error(A, D, B, C, s, t) )
err++;
else
ok++;
}
}
CCLog("Test1 - End. OK=%i, Err=%i", ok, err);

//
// Test 2.
//
CCLog("Test2 - Start");

p1 = ccp(220,480);
p2 = ccp(304,325);
p3 = ccp(264,416);
p4 = ccp(186,416);
s = 0.0f;
t = 0.0f;
if( ccpLineIntersect(p1, p2, p3, p4, &s, &t) )
check_for_error(p1, p2, p3, p4, s,t );

CCLog("Test2 - End");


//
// Test 3
//
CCLog("Test3 - Start");

ok=0;
err=0;
for( int i=0;i<10000;i++)
{
// A | b
// -----
// c | d
float ax = CCRANDOM_0_1() * -500;
float ay = CCRANDOM_0_1() * 500;
p1 = ccp(ax,ay);

// a | b
// -----
// c | D
float dx = CCRANDOM_0_1() * 500;
float dy = CCRANDOM_0_1() * -500;
p2 = ccp(dx,dy);


//////

float y = ay - ((ay - dy) /2.0f);

// a | b
// -----
// C | d
float cx = CCRANDOM_0_1() * -500;
p3 = ccp(cx,y);

// a | B
// -----
// c | d
float bx = CCRANDOM_0_1() * 500;
p4 = ccp(bx,y);

s = 0.0f;
t = 0.0f;
if( ccpLineIntersect(p1, p2, p3, p4, &s, &t) ) {
if( check_for_error(p1, p2, p3, p4, s,t ) )
err++;
else
ok++;
}
}

CCLog("Test3 - End. OK=%i, err=%i", ok, err);
return true;
}

return false;
}
12 changes: 12 additions & 0 deletions tests/tests/BugsTest/Bug-1174.h
@@ -0,0 +1,12 @@
#ifndef __BUG_1174_H__
#define __BUG_1174_H__

#include "BugsTest.h"

class Bug1174Layer : public BugsTestBaseLayer
{
public:
virtual bool init();
};

#endif // __BUG_1174_H__
20 changes: 20 additions & 0 deletions tests/tests/BugsTest/Bug-350.cpp
@@ -0,0 +1,20 @@
//
// Bug-350
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=350
//

#include "Bug-350.h"

bool Bug350Layer::init()
{
if (BugsTestBaseLayer::init())
{
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSprite *background = CCSprite::spriteWithFile("Default.png");
background->setPosition(ccp(size.width/2, size.height/2));
addChild(background);
return true;
}

return false;
}

0 comments on commit eab0802

Please sign in to comment.