
35 Cal.2d 389 (1950)
TOMALES BAY OYSTER CORPORATION (a Corporation), Petitioner,
v.
THE SUPERIOR COURT OF THE CITY AND COUNTY OF SAN FRANCISCO, Respondent; JAMES G. BRYANT, Director of Employment, etc., Real Party in Interest.
S. F. No. 17963. 
Supreme Court of California. In Bank.  
May 9, 1950.
 Fabian D. Brown for Petitioner.
 Fred N. Howser, Attorney General, ChaS.W. Johnson and William L. Shaw, Deputy Attorneys General, for Respondent and Real Party in Interest.
 GIBSON, C.J.
 Petitioner seeks a writ of prohibition to stay further proceedings under a cross-pleading filed by the California Employment Stabilization Commission in an action brought by petitioner against the commission. *391
 On January 4, 1943, petitioner commenced an action to recover $20 unemployment insurance contributions paid under protest, alleging that it was not an employer subject to the Unemployment Insurance Act. On March 13, 1943, the commission filed a pleading, entitled "Answer and Counterclaim," which set forth a cause of action "by way of counter-claim" for further taxes and penalties due in the sum of $1,474.02, together with interest and costs. Immediately thereafter the parties entered into a stipulation that petitioner might have 10 days after written notice to answer or otherwise plead to "defendant's cross-complaint." On February 18, 1948, the commission gave notice to plead "to the cross-complaint," and petitioner's answer was filed on February 27. The trial was commenced on March 5, 1948, "upon the pleading of defendant," and the commission introduced evidence, both oral and documentary, in support of its claim and rested its case. The cause was then continued at petitioner's request until April 23, at which time petitioner's cause of action upon its complaint was dismissed on motion by the commission based on section 583 of the Code of Civil Procedure.  [fn. *] The trial was completed on the issues raised by the commission's pleading, and judgment was entered for petitioner. The commission, however, was granted a new trial on December 16, 1948, and no appeal was taken from this order.
 When the cause was called for retrial, on February 17, 1949, petitioner moved to dismiss the action set forth in the commission's pleading on the ground that it had not been brought to trial within five years after petitioner's complaint was filed. Trial on the commission's pleading, however, had been commenced within five years after it was filed, and the motion was denied. Petitioner then applied for a writ of prohibition to prevent respondent superior court from proceeding with the trial. An alternative writ was issued and further proceedings were stayed pending determination of whether the application for a peremptory writ should be granted.
 Petitioner contends that the commission's pleading was merely a counterclaim and a part of the answer which fell with dismissal of the complaint, and that the trial court had no jurisdiction to proceed with the trial because there was *392 nothing before it. He also argues in effect that trial on the cross-pleading was barred under section 583 of the Code of Civil Procedure because the five-year period had run against the complaint.
 [1] A preliminary question is presented as to the propriety of the use of the writ to test the jurisdiction of the court to proceed with the trial. It would seem clear that if the commission's pleading fell with dismissal of the complaint, leaving nothing before the trial court, it was without jurisdiction to proceed. Likewise, if the court is proceeding erroneously after expiration of the time prescribed by section 583 of the Code of Civil Procedure, it is acting in excess of its jurisdiction, and prohibition will lie to prevent a retrial of the action if there is no other plain, speedy and adequate remedy at law. (Cf., Superior Oil Co. v. Superior Court, 6 Cal.2d 113 [56 P.2d 950]; Andersen v. Superior Court, 187 Cal. 95, 97 [200 P. 963]; White v. Superior Court, 126 Cal. 245 [58 P. 450]; Rio Del Mar etc. Club, Inc. v. Superior Court, 84 Cal.App.2d 214 [190 P.2d 295].)
 [2] The problem presented here was, of course, not included as a ground of the commission's motion for a new trial, nor was it ruled on by the court in granting the motion. It therefore could not be considered upon an appeal from the order granting a new trial. (See Byxbee v. Dewey, 128 Cal. 322 [60 P. 847]; Holmes v. Warren, 145 Cal. 457, 460 [78 P. 954]; 2 Cal.Jur. 828-830.) [3] The order refusing to dismiss the action was not appealable, and to compel petitioner to submit to an unwarranted retrial of the cause, and then appeal from the judgment if adverse to it, would not afford speedy or adequate relief. (Andersen v. Superior Court, 187 Cal. 95, 97 [200 P. 963]; see, also, Superior Oil Co. v. Superior Court, 6 Cal.2d 113, 119 [56 P.2d 950].) The writ may therefore be used to test the jurisdiction of the trial court.
 In considering petitioner's contention that the commission's cross- pleading fell with the dismissal of the complaint and that trial of the cross-action was barred under section 583 of the Code of Civil Procedure, we must look to the character of the pleading and the purposes of the section. When the commission's pleading was filed it was denominated a counterclaim, but thereafter it was called and treated as a cross-complaint. [4] The nature and character of a pleading, however, is to be determined from its allegations, regardless of what it may be called by the parties, and it has been held that when a pleading meets the requirements of both a *393 counterclaim and a cross-complaint the court may, in its discretion, treat it as either, to the end that substantial justice may be done. (Schrader v. Neville, 34 Cal.2d 112, 113-115 [207 P.2d 1057]; Terry Trading Corp. v. Barsky, 210 Cal. 428, 434 [292 P. 474]; see 10 So.Cal.L.Rev. [1937] 415, 420, 447-448.)
 [5] The commission's pleading seeks both to defeat petitioner's demand and to recover a money judgment in excess of that demand. Under section 438 of the Code of Civil Procedure, a counterclaim "must tend to diminish or defeat the plaintiff's recovery and must exist in favor of a defendant and against a plaintiff between whom a several judgment might be had, ..." and it has been held that it may include the right to affirmative relief for damages where the original complaint prayed for a money judgment. (Todhunter v. Smith, 219 Cal. 690, 693 [28 P.2d 916]; Terry Trading Corp. v. Barsky, 210 Cal. 428, 438 [292 P. 474].) A counterclaim may arise out of the transaction set forth in the complaint as the foundation of plaintiff's claim, and if it does the defendant must set it up or be forever barred. (Code Civ. Proc.,  439; see Schrader v. Neville, 34 Cal.2d 112 [207 P.2d 1057].) The pleading of the commission therefore comes within the definition of a counterclaim. [6] However, it also falls within the requirements for a cross-complaint. Section 442 of the Code of Civil Procedure provides that a cross-complaint may be filed whenever the defendant seeks affirmative relief against any party relating to or depending upon the transaction or matter upon which the action is brought. The relief sought by the commission related to the same transaction or matter upon which the action was brought, and the pleading is thus within the express wording of the statute.
 It follows that the commission's claim is one which could have been pleaded either as a counterclaim or as a cross-complaint. Under such circumstances, as we have seen, the court may treat it as either, and here, since the commission's pleading meets the requirements for a cross-complaint, and the parties treated it as a cross-complaint after it was filed, there appears to be no good reason why we should not likewise treat it as such.
 [7] It is clear that a cross-complaint is not subject to mandatory dismissal under section 583 until the lapse of five years from the filing of the cross-complaint. (See Pacific Finance Corp. v. Superior Court, 219 Cal. 179, 182-183 [25 *394 P.2d 983, 90 A.L.R. 384]; Douglas v. Superior Court, 94 Cal.App.2d 395, 397-398 [210 P.2d 713].) In the Pacific Finance case, supra, it was said that the code provisions permitting the settlement of cross-claims between the same parties in the same action, in order to prevent a multiplicity of actions, did not change the fact that, for purposes of mandatory dismissal under section 583, "these cross actions ... are still distinct and independent causes of action, so that when properly interposed and stated the defendant becomes in respect to the matters pleaded by him, an actor, and there are two simultaneous actions pending between the same parties wherein each is at the same time both a plaintiff and a defendant." (219 Cal. at p. 182.) The court relied in part on the provisions of section 581 of the Code of Civil Procedure that a plaintiff could voluntarily dismiss an action unless affirmative relief was sought by the cross-complaint or the answer of defendant, and it concluded that the plaintiff had no such control over a cross-complaint as would entitle him to seek its dismissal under section 583 until five years after the filing of the answer thereto.  [fn. *]
 [8] It follows that if the commission's pleading is treated as a cross-complaint, it did not fall upon dismissal of the complaint, and the court was not required to dismiss the cross-complaint because trial thereon was commenced within five years after it was filed. Hence the court was within its jurisdiction in proceeding with the trial.
 It is not necessary, however, to place our decision on the ground that the pleading here involved is a cross-complaint. We are of the opinion that the same result should obtain if that pleading be considered as a counterclaim which seeks affirmative relief. All the reasoning of the Pacific Finance case is equally applicable to such a counterclaim since, insofar as a cause of action is stated, it is in fact a separate action which could have been separately brought and tried (See Sooy v. Cerf, 220 Cal. 611, 619 [32 P.2d 365]; Belleau v. Thompson, 33 Cal. 495.) As we have seen, the commission's *395 pleading does not seek merely to defeat or diminish petitioner's claim; it also seeks affirmative relief greatly in excess of that demanded by petitioner, and there is no doubt that a separate action could have been maintained by the commission if petitioner had not previously commenced its action.
 Moreover, subdivision 5 of section 581 of the Code of Civil Procedure provides that a plaintiff may voluntarily dismiss his cause of action with prejudice prior to trial, but that the dismissal does not have the effect of dismissing a cross-complaint or counterclaim or of depriving the defendant of affirmative relief sought by his answer. In view of this statutory policy it is obvious that a plaintiff should not be allowed to assert any greater rights merely because he has adopted a course of inaction which eventually results in the involuntary dismissal of his complaint under section 583, and, therefore, he should not be entitled to claim that the involuntary dismissal of his complaint constitutes or requires dismissal of a counterclaim wherein defendant seeks affirmative relief. To hold that such a counterclaim is subject to mandatory dismissal five years after the complaint is filed would in effect penalize an answering pleader by giving him less time to act after the filing of his pleading than he would have if he had brought an independent action, and thus it would be incompatible with the policy of avoiding a multiplicity of actions and of encouraging the settlement of all claims between the parties in a single proceeding whenever possible.
 [9] We conclude, therefore, that whether the commission's pleading be treated as a cross-complaint or a counterclaim, the commission became an independent actor upon filing its pleading seeking affirmative relief, that the commission had five years from the filing of its pleading in which to bring its action to trial, and that the dismissal as to the complaint did not constitute or require a dismissal of the issues raised by the commission's pleading.
 The alternative writ is discharged, and the peremptory writ is denied.
 Shenk, J., Edmonds, J., Carter, J., Traynor, J., Schauer, J., and Spence, J., concurred.
NOTES
[fn. *]  *. Code Civ. Proc.,  583, provides that an action shall be dismissed on noticed motion, or by the court on its own motion, "unless such action is brought to trial within five years after the plaintiff has filed his action, except where the parties have filed a stipulation in writing that the time may be extended. ..."
[fn. *]  *. When the dismissal was ordered in the Pacific Finance case the five year period ran from the filing of defendant's answer. Section 583 was later amended to make the period run from the filing of plaintiff's complaint. The amendment does not impair the effect of the reasoning in that case but, instead, makes it clear that the time for bringing any cause of action to trial, whether by complaint or cross-complaint, runs from the first assertion of the cause of action, i.e., the filing of the particular pleading. (See Douglas v. Superior Court, 194 Cal.App.2d 395, 397-398 [210 P.2d 713].) [1Advance Report Citation: 94 A.C.A. 430, 432-433.]
