Skip to content

Commit 002dcf2

Browse files
PatriceJianghuangwei1024
authored andcommitted
cpp-tests/Bugs add titles & lua bugs/1174 decrease loop count (cocos2d#19205)
* cpp-tests/Bugs add titles & lua bugs/1174 decrease loop count * reduce loop times to 1000
1 parent 503ce50 commit 002dcf2

File tree

19 files changed

+99
-34
lines changed

19 files changed

+99
-34
lines changed

cocos/platform/android/CCFileUtils-android.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ bool FileUtilsAndroid::isDirectoryExistInternal(const std::string& dirPath) cons
229229
{
230230
// find it in apk's assets dir
231231
// Found "assets/" at the beginning of the path and we don't want it
232-
CCLOG("find in apk dirPath(%s)", s);
232+
//CCLOG("find in apk dirPath(%s)", s);
233233
if (dirPath.find(ASSETS_FOLDER_NAME) == 0)
234234
{
235235
s += ASSETS_FOLDER_NAME_LENGTH;

cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_manual.cpp

+71
Original file line numberDiff line numberDiff line change
@@ -8540,6 +8540,75 @@ static int tolua_cocos2d_Vec3_cross(lua_State* tolua_S)
85408540
#endif
85418541
}
85428542

8543+
static int tolua_cocos2d_random01(lua_State* tolua_S)
8544+
{
8545+
lua_pushnumber(tolua_S, CCRANDOM_0_1());
8546+
return 1;
8547+
}
8548+
8549+
static int tolua_cocos2d_Vec2_isLineIntersect(lua_State* tolua_S)
8550+
{
8551+
int argc = lua_gettop(tolua_S);
8552+
8553+
#if COCOS2D_DEBUG >= 1
8554+
tolua_Error tolua_err;
8555+
#endif
8556+
8557+
if (4 == argc)
8558+
{
8559+
#if COCOS2D_DEBUG >= 1
8560+
if (!tolua_istable(tolua_S, 1, 0, &tolua_err) ||
8561+
!tolua_istable(tolua_S, 2, 0, &tolua_err) ||
8562+
!tolua_istable(tolua_S, 3, 0, &tolua_err)||
8563+
!tolua_istable(tolua_S, 4, 0, &tolua_err))
8564+
goto tolua_lerror;
8565+
else
8566+
#endif
8567+
{
8568+
cocos2d::Vec2 x1,y1;
8569+
cocos2d::Vec2 x2,y2;
8570+
8571+
float s =0.0f, t = 0.0f;
8572+
8573+
bool ok = true;
8574+
8575+
ok &= luaval_to_vec2(tolua_S, 1, &x1);
8576+
if (!ok)
8577+
return 0;
8578+
8579+
ok &= luaval_to_vec2(tolua_S, 2, &y1);
8580+
if (!ok)
8581+
return 0;
8582+
8583+
ok &= luaval_to_vec2(tolua_S, 3, &x2);
8584+
if (!ok)
8585+
return 0;
8586+
8587+
ok &= luaval_to_vec2(tolua_S, 4, &y2);
8588+
if (!ok)
8589+
return 0;
8590+
8591+
bool intersects = Vec2::isLineIntersect(x1, y1, x2, y2, &s, &t);
8592+
8593+
lua_pushboolean(tolua_S, intersects);
8594+
lua_pushnumber(tolua_S, s);
8595+
lua_pushnumber(tolua_S, t);
8596+
return 3;
8597+
}
8598+
}else
8599+
{
8600+
lua_pushboolean(tolua_S, false);
8601+
lua_pushnumber(tolua_S, 0);
8602+
lua_pushnumber(tolua_S, 0);
8603+
return 3;
8604+
}
8605+
#if COCOS2D_DEBUG >= 1
8606+
tolua_lerror:
8607+
tolua_error(tolua_S,"#ferror in function 'vec2_isLineIntersect'.",&tolua_err);
8608+
return 0;
8609+
#endif
8610+
}
8611+
85438612
static int tolua_cocos2d_Mat4_multiply(lua_State* tolua_S)
85448613
{
85458614
#if COCOS2D_DEBUG >= 1
@@ -8825,6 +8894,8 @@ int register_all_cocos2dx_math_manual(lua_State* tolua_S)
88258894
tolua_function(tolua_S, "mat4_createTranslation", tolua_cocos2d_Mat4_createTranslation);
88268895
tolua_function(tolua_S, "mat4_createRotation", tolua_cocos2d_Mat4_createRotation);
88278896
tolua_function(tolua_S, "vec3_cross", tolua_cocos2d_Vec3_cross);
8897+
tolua_function(tolua_S, "vec2_isLineIntersect", tolua_cocos2d_Vec2_isLineIntersect);
8898+
tolua_function(tolua_S, "cc_mathutils_random", tolua_cocos2d_random01);
88288899
tolua_endmodule(tolua_S);
88298900
return 0;
88308901
}

cocos/scripting/lua-bindings/script/cocos2d/Cocos2d.lua

+6-27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11

22
cc = cc or {}
33

4+
5+
function cc.random()
6+
return cc_mathutils_random()
7+
end
8+
49
function cc.clampf(value, min_inclusive, max_inclusive)
510
-- body
611
local temp = 0
@@ -89,33 +94,7 @@ function cc.pGetDistance(startP,endP)
8994
end
9095

9196
function cc.pIsLineIntersect(A, B, C, D, s, t)
92-
if ((A.x == B.x) and (A.y == B.y)) or ((C.x == D.x) and (C.y == D.y))then
93-
return false, s, t
94-
end
95-
96-
local BAx = B.x - A.x
97-
local BAy = B.y - A.y
98-
local DCx = D.x - C.x
99-
local DCy = D.y - C.y
100-
local ACx = A.x - C.x
101-
local ACy = A.y - C.y
102-
103-
local denom = DCy * BAx - DCx * BAy
104-
s = DCx * ACy - DCy * ACx
105-
t = BAx * ACy - BAy * ACx
106-
107-
if (denom == 0) then
108-
if (s == 0 or t == 0) then
109-
return true, s , t
110-
end
111-
112-
return false, s, t
113-
end
114-
115-
s = s / denom
116-
t = t / denom
117-
118-
return true,s,t
97+
return vec2_isLineIntersect(A, B, C, D)
11998
end
12099

121100
function cc.pPerp(pt)

tests/cpp-tests/Classes/BugsTest/Bug-1159.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Bug1159Layer : public BugsTestBase
3232
public:
3333
virtual bool init() override;
3434
virtual void onExit() override;
35+
virtual std::string title() const override { return "Bug1159";}
3536

3637
void callBack(cocos2d::Ref* sender);
3738

tests/cpp-tests/Classes/BugsTest/Bug-1174.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class Bug1174Layer : public BugsTestBase
3131
{
3232
public:
3333
CREATE_FUNC(Bug1174Layer);
34-
34+
virtual std::string title() const override { return "Bug1174";}
35+
virtual std::string subtitle() const override {return "view console output";}
3536
virtual bool init() override;
3637
};
3738

tests/cpp-tests/Classes/BugsTest/Bug-12847.h

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Bug12847Layer : public BugsTestBase
3434

3535
virtual bool init() override;
3636

37+
virtual std::string title() const override { return "12874";}
3738
protected:
3839
virtual void update(float dt) override;
3940
virtual void onEnter() override;

tests/cpp-tests/Classes/BugsTest/Bug-14327.h

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Bug14327Layer : public BugsTestBase, public cocos2d::ui::EditBoxDelegate
3535
CREATE_FUNC(Bug14327Layer);
3636

3737
virtual bool init() override;
38+
virtual std::string title() const override { return "Bug14327";}
3839

3940
virtual void editBoxEditingDidBegin(cocos2d::ui::EditBox* editBox) override;
4041
virtual void editBoxEditingDidEnd(cocos2d::ui::EditBox* editBox) override;

tests/cpp-tests/Classes/BugsTest/Bug-15594.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Bug15594Layer : public BugsTestBase
3232
{
3333
public:
3434
CREATE_FUNC(Bug15594Layer);
35+
virtual std::string title() const override { return "Bug15594";}
3536

3637
virtual bool init() override;
3738
};

tests/cpp-tests/Classes/BugsTest/Bug-15776.h

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class Bug15776Layer : public BugsTestBase
4141
CREATE_FUNC(Bug15776Layer);
4242

4343
virtual bool init() override;
44-
4544
virtual std::string title() const override;
4645
virtual std::string subtitle() const override;
4746
};

tests/cpp-tests/Classes/BugsTest/Bug-350.h

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Bug350Layer : public BugsTestBase
3333
CREATE_FUNC(Bug350Layer);
3434

3535
virtual bool init() override;
36+
virtual std::string title() const override { return "Bug350";}
3637
};
3738

3839
#endif // __BUG_350_H__

tests/cpp-tests/Classes/BugsTest/Bug-422.h

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Bug422Layer : public BugsTestBase
3434

3535
virtual bool init() override;
3636

37+
virtual std::string title() const override { return "Bug422";}
3738
void reset();
3839
void check(Node* target);
3940
void menuCallback(cocos2d::Ref* sender);

tests/cpp-tests/Classes/BugsTest/Bug-624.h

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Bug624Layer : public BugsTestBase
3535
void switchLayer(float dt);
3636
virtual void onAcceleration(cocos2d::Acceleration* acc, cocos2d::Event* event);
3737

38+
virtual std::string title() const override { return "Bug624";}
3839
CREATE_FUNC(Bug624Layer);
3940
};
4041

@@ -44,6 +45,8 @@ class Bug624Layer2 : public BugsTestBase
4445
virtual ~Bug624Layer2();
4546
virtual bool init() override;
4647
void switchLayer(float dt);
48+
virtual std::string title() const override { return "Bug624-2";}
49+
4750
virtual void onAcceleration(cocos2d::Acceleration* acc, cocos2d::Event* event);
4851

4952
CREATE_FUNC(Bug624Layer2);

tests/cpp-tests/Classes/BugsTest/Bug-886.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Bug886Layer : public BugsTestBase
3232
public:
3333
CREATE_FUNC(Bug886Layer);
3434

35+
virtual std::string title() const override { return "Bug886";}
3536
virtual bool init() override;
3637
};
3738

tests/cpp-tests/Classes/BugsTest/Bug-899.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Bug899Layer : public BugsTestBase
3232
public:
3333
CREATE_FUNC(Bug899Layer);
3434

35+
virtual std::string title() const override { return "Bug899";}
3536
virtual bool init() override;
3637
};
3738

tests/cpp-tests/Classes/BugsTest/Bug-914.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Bug914Layer : public BugsTestBase
3232
public:
3333
virtual bool init() override;
3434

35+
virtual std::string title() const override { return "Bug914";}
3536
void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
3637
void onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
3738
void restart(cocos2d::Ref* sender);

tests/cpp-tests/Classes/BugsTest/Bug-CCDrawNode.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class BugDrawNodeLayer : public BugsTestBase
3232
public:
3333
CREATE_FUNC(BugDrawNodeLayer);
3434

35+
virtual std::string title() const override { return "BugDrawNode";}
3536
virtual bool init() override;
3637
};
3738

38-
#endif
39+
#endif

tests/cpp-tests/Classes/BugsTest/Bug-Child.h

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class BugChild : public BugsTestBase
4141
CREATE_FUNC(BugChild);
4242

4343
virtual bool init() override;
44+
virtual std::string title() const override { return "BugChild";}
4445

4546
void switchChild(cocos2d::Ref* sender);
4647

@@ -61,6 +62,7 @@ class BugCameraMask : public BugsTestBase
6162

6263
virtual bool init() override;
6364

65+
virtual std::string title() const override { return "BugCameraMask";}
6466
void switchSpriteFlag(cocos2d::Ref* sender);
6567
void updateSpriteMaskLabel();
6668
Node* _sprite;

tests/cpp-tests/Classes/BugsTest/BugsTest.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
class BugsTestBase : public TestCase
3131
{
3232
public:
33-
33+
virtual std::string title() const override {return "No Test Title set";}
3434
};
3535

3636
DEFINE_TEST_SUITE(BugsTests);

tests/lua-tests/src/BugsTest/BugsTest.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ local function BugTest1174()
441441

442442
print("Test1 - Start")
443443
local i = 0
444-
for i = 0, 9999 do
444+
for i = 0, 999 do
445445
--[[
446446
A|b
447447
-----
@@ -513,7 +513,7 @@ local function BugTest1174()
513513

514514
ok=0
515515
err=0
516-
for i = 0 , 9999 do
516+
for i = 0 , 999 do
517517
-- A | b
518518
-- -----
519519
-- c | d

0 commit comments

Comments
 (0)